$human3->save(); $finder = sfPropelFinder::from('Human')-> join('Human father', 'Human.FatherId', 'father.Id', 'INNER JOIN')-> join('Human mother', 'Human.MotherId', 'mother.Id', 'INNER JOIN')-> where('father.Name', 'John')-> where('mother.Name', 'Jane'); $nbHumans = $finder->count(); $t->is($nbHumans, 1, 'join() allows to join to the current table with several foreign keys using an alias'); $t->is($finder->getLatestQuery(), propel_sql('SELECT COUNT([P13*][P12human.ID]) FROM human INNER JOIN human father ON (human.FATHER_ID=father.ID) INNER JOIN human mother ON (human.MOTHER_ID=mother.ID) WHERE (father.NAME=\'John\' AND mother.NAME=\'Jane\')'), 'join() uses aliased table names when using an alias relation'); HumanPeer::doDeleteAll(); $human1 = new Human(); $human1->setName('John'); $human1->save(); $human2 = new Human(); $human2->setName('Albert'); $human2->setHumanRelatedByFatherId($human1); $human2->save(); $human3 = new Human(); $human3->setName('Jane'); $human3->setHumanRelatedByFatherId($human2); $human3->save(); $finder = sfPropelFinder::from('Human')-> join('Human father', 'Human.FatherId', 'father.Id', 'INNER JOIN')-> join('Human grandfather', 'father.FatherId', 'grandfather.Id', 'INNER JOIN')-> where('grandfather.Name', 'John'); $nbHumans = $finder->count(); $t->is($nbHumans, 1, 'join() allows to join to the current table with several foreign keys using an alias'); $t->is($finder->getLatestQuery(), propel_sql('SELECT COUNT([P13*][P12human.ID]) FROM human INNER JOIN human father ON (human.FATHER_ID=father.ID) INNER JOIN human grandfather ON (father.FATHER_ID=grandfather.ID) WHERE grandfather.NAME=\'John\''), 'join() uses aliased table names when using an alias relation');
$t->is($house->getHumanRelatedByRenterId()->getName(), 'Jane', 'with() with multiple foreign keys to the same table hydrates the related objects'); $t->is(Propel::getConnection()->getLastExecutedQuery(), $sql, 'with() with multiple foreign keys to the same table avoids subsequent queries'); /************************************************************/ /* sfPropelFinder::with() with self-referenced foreign keys */ /************************************************************/ $t->diag('sfPropelFinder::with() with self-referenced foreign keys'); HumanPeer::doDeleteAll(); $human1 = new Human(); $human1->setName('John'); $human1->save(); $human2 = new Human(); $human2->setName('Albert'); $human2->setHumanRelatedByFatherId($human1); $human2->save(); $finder = sfPropelFinder::from('Human')-> join('Human father', 'Human.FatherId', 'father.Id', 'INNER JOIN')-> with('father')-> where('father.Name', 'John'); $human = $finder->findOne(); $sql = 'SELECT human.ID, human.NAME, human.FATHER_ID, human.MOTHER_ID, human.THE_SEX, father.ID, father.NAME, father.FATHER_ID, father.MOTHER_ID, father.THE_SEX FROM human INNER JOIN human father ON (human.FATHER_ID=father.ID) WHERE father.NAME=\'John\' LIMIT 1'; $t->is($finder->getLatestQuery(), $sql, 'with() adds the correct columns to the query when called with self-referenced foreign keys'); $t->is($human->getName(), 'Albert', 'with() with self-referenced foreign keys does not change the main object hyration'); $t->is($human->getHumanRelatedByFatherId()->getName(), 'John', 'with() with self-referenced foreign keys hydrates the related objects'); $t->is(Propel::getConnection()->getLastExecutedQuery(), $sql, 'with() with self-referenced foreign keys avoids subsequent queries'); /******************************/ /* sfPropelFinder::withI18n() */