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');
$t->diag('sfPropelFinderRelation::getObjectToRelate() 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->setCivility($civility1); $human1->save(); $house1 = new House(); $house1->setName('Home1'); $house1->setHumanRelatedByOwnerId($human1); $house1->save(); $manager = new sfPropelFinderRelationManager('House'); $ownerRelation = $manager->addRelationFromColumns('House', HousePeer::OWNER_ID, 'Human', HumanPeer::ID, 'owner'); $civilityRelation = $manager->guessRelation('Civility'); $manager[] = $civilityRelation; $obj1 = $ownerRelation->getObjectToRelate($house1); $t->isa_ok($obj1, 'House', 'getObjectToRelate() returns the object passed as parameter when the relation has no previous relation'); $obj2 = $civilityRelation->getObjectToRelate($house1); $t->isa_ok($obj2, 'Human', 'getObjectToRelate() returns a Propel model object'); $t->is($obj2->getName(), 'John', 'getObjectToRelate() returns the object resulting from the previous relation'); HumanPeer::doDeleteAll(); $human1 = new Human();