/*************************************************************************/
/* sfPropelFinderRelation::getObjectToRelate() and multiple 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');