public function testSetRelationMapComposite()
 {
     $table = ReaderFavoriteTableMap::getTableMap();
     $join = new ModelJoin();
     $join->setTableMap($table);
     $join->setRelationMap($table->getRelation('BookOpinion'));
     $this->assertEquals(array(ReaderFavoriteTableMap::COL_BOOK_ID, ReaderFavoriteTableMap::COL_READER_ID), $join->getLeftColumns(), 'setRelationMap() automatically sets the left columns for composite relationships');
     $this->assertEquals(array(BookOpinionTableMap::COL_BOOK_ID, BookOpinionTableMap::COL_READER_ID), $join->getRightColumns(), 'setRelationMap() automatically sets the right columns for composite relationships');
 }
 public function testUseFkQueryTwiceTwoAliases()
 {
     $q = BookQuery::create()->useAuthorQuery('a')->filterByFirstName('Leo')->endUse()->useAuthorQuery('b')->filterByLastName('Tolstoi')->endUse();
     $join1 = new ModelJoin();
     $join1->setJoinType(Criteria::LEFT_JOIN);
     $join1->setTableMap(AuthorTableMap::getTableMap());
     $join1->setRelationMap(BookTableMap::getTableMap()->getRelation('Author'), null, 'a');
     $join1->setRelationAlias('a');
     $join2 = new ModelJoin();
     $join2->setJoinType(Criteria::LEFT_JOIN);
     $join2->setTableMap(AuthorTableMap::getTableMap());
     $join2->setRelationMap(BookTableMap::getTableMap()->getRelation('Author'), null, 'b');
     $join2->setRelationAlias('b');
     $q1 = BookQuery::create()->addAlias('a', AuthorTableMap::TABLE_NAME)->addJoinObject($join1, 'a')->add('a.FIRST_NAME', 'Leo', Criteria::EQUAL)->addAlias('b', AuthorTableMap::TABLE_NAME)->addJoinObject($join2, 'b')->add('b.LAST_NAME', 'Tolstoi', Criteria::EQUAL);
     $this->assertTrue($q->equals($q1), 'useFkQuery() called twice on the same relation with two aliases creates two joins');
 }
예제 #3
0
 /**
  * @param \Orm\Zed\Glossary\Persistence\SpyGlossaryKeyQuery $keyQuery
  * @param array $relevantLocales
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 protected function joinKeyQueryWithRelevantLocalesAndTranslations(SpyGlossaryKeyQuery $keyQuery, array $relevantLocales)
 {
     $keyLocaleCrossJoin = new ModelJoin();
     $keyLocaleCrossJoin->setJoinType(Criteria::JOIN);
     /*
      * @param string $value
      *
      * @return string
      */
     $quoteFunction = function ($value) {
         return "'{$value}'";
     };
     $quotedLocales = array_map($quoteFunction, $relevantLocales);
     $keyLocaleCrossJoin->setTableMap(new TableMap())->setLeftTableName('spy_glossary_key')->setRightTableName('spy_locale')->addCondition('id_glossary_key', 'id_locale', ModelCriteria::NOT_EQUAL);
     $translationLeftJoin = new ModelJoin();
     $translationLeftJoin->setJoinType(Criteria::LEFT_JOIN);
     $translationLeftJoin->setTableMap(new TableMap())->setLeftTableName('spy_glossary_key')->setRightTableName('spy_glossary_translation')->addCondition('id_glossary_key', 'fk_glossary_key');
     return $keyQuery->addJoinObject($keyLocaleCrossJoin, 'spy_locale')->addJoinObject($translationLeftJoin, 'spy_glossary_translation')->addJoinCondition('spy_glossary_translation', 'spy_locale.id_locale = spy_glossary_translation.fk_locale')->addJoinCondition('spy_locale', 'spy_locale.locale_name  IN (' . implode($quotedLocales, ', ') . ')');
 }