HumanPeer::doDeleteAll(); HousePeer::doDeleteAll(); $human1 = new Human(); $human1->setName('John'); $human1->save(); $human2 = new Human(); $human2->setName('Jane'); $human2->save(); $house1 = new House(); $house1->setName('Home1'); $house1->setHumanRelatedByOwnerId($human1); $house1->setHumanRelatedByRenterId($human2); $house1->save(); $house2 = new House(); $house2->setName('Home2'); $house2->setHumanRelatedByOwnerId($human2); $house2->setHumanRelatedByRenterId($human1); $house2->save(); $finder = sfPropelFinder::from('House')-> join('Human owner', 'House.OwnerId', 'owner.Id', 'INNER JOIN')-> where('owner.Name', 'John'); $nbHouses = $finder->count(); $t->is($nbHouses, 1, 'join() allows to join to another table with several foreign keys using an alias'); $t->is($finder->getLatestQuery(), propel_sql('SELECT COUNT([P13*][P12house.ID]) FROM house INNER JOIN human owner ON (house.OWNER_ID=owner.ID) WHERE owner.NAME=\'John\''), 'join() uses aliased table names when using an alias relation'); /************************************************************/ /* sfPropelFinder::join() with self-referenced foreign keys */ /************************************************************/ $t->diag('sfPropelFinder::join() with self-referenced foreign keys');
/* sfPropelFinderRelation::relateObject() and multiple foreign keys */ /********************************************************************/ $t->diag('sfPropelFinderRelation::relateObject() and multiple foreign keys'); CivilityPeer::doDeleteAll(); HumanPeer::doDeleteAll(); HousePeer::doDeleteAll(); $civility1 = new Civility(); $civility1->setIsMan(true); $civility1->save(); $human1 = new Human(); $human1->setName('John'); $human1->save(); $house1 = new House(); $house1->setName('Home1'); $house1->save(); $manager = new sfPropelFinderRelationManager('House'); $ownerRelation = $manager->addRelationFromColumns('House', HousePeer::OWNER_ID, 'Human', HumanPeer::ID, 'owner'); $civilityRelation = $manager->guessRelation('Civility'); $manager[] = $civilityRelation; $ownerRelation->relateObject($house1, $human1); $t->is($house1->getOwnerId(), $human1->getId(), 'relateObject() creates a relation between two Propel objects'); $civilityRelation->relateObject($house1, $civility1); $t->is($human1->getTheSex(), $civility1->getId(), 'relateObject() creates a relation between two Propel objects via another relation'); /******************************************************/ /* sfPropelFinderRelation::relateObject() and aliases */ /******************************************************/