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'); }
/** * Define the joined hydration schema based on a join object. * Fills the ModelWith properties using a ModelJoin as source * * @param ModelJoin $join */ public function init(ModelJoin $join) { $tableMap = $join->getTableMap(); $this->setModelName($tableMap->getClassName()); $this->getTableMap = $tableMap; $this->isSingleTableInheritance = $tableMap->isSingleTableInheritance(); $relation = $join->getRelationMap(); $relationName = $relation->getName(); if ($relation->getType() == RelationMap::ONE_TO_MANY) { $this->isAdd = $this->isWithOneToMany = true; $this->relationName = $relation->getPluralName(); $this->relationMethod = 'add' . $relationName; $this->initMethod = 'init' . $this->relationName; $this->resetPartialMethod = 'resetPartial' . $this->relationName; } else { $this->relationName = $relationName; $this->relationMethod = 'set' . $relationName; } $this->rightPhpName = $join->hasRelationAlias() ? $join->getRelationAlias() : $relationName; if (!$join->isPrimary()) { $this->leftPhpName = $join->hasLeftTableAlias() ? $join->getLeftTableAlias() : $join->getPreviousJoin()->getRelationMap()->getName(); } }
/** * Adds a JOIN clause to the query using the GoogleshoppingAccount relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return ChildGoogleshoppingProductSynchronisationQuery The current query, for fluid interface */ public function joinGoogleshoppingAccount($relationAlias = null, $joinType = Criteria::INNER_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('GoogleshoppingAccount'); // create a ModelJoin object for this join $join = new ModelJoin(); $join->setJoinType($joinType); $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); if ($previousJoin = $this->getPreviousJoin()) { $join->setPreviousJoin($previousJoin); } // add the ModelJoin to the current object if ($relationAlias) { $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { $this->addJoinObject($join, 'GoogleshoppingAccount'); } return $this; }
/** * Adds a JOIN clause to the query using the CustomerTitle relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return ChildCustomerTitleI18nQuery The current query, for fluid interface */ public function joinCustomerTitle($relationAlias = null, $joinType = 'LEFT JOIN') { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('CustomerTitle'); // create a ModelJoin object for this join $join = new ModelJoin(); $join->setJoinType($joinType); $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); if ($previousJoin = $this->getPreviousJoin()) { $join->setPreviousJoin($previousJoin); } // add the ModelJoin to the current object if ($relationAlias) { $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { $this->addJoinObject($join, 'CustomerTitle'); } return $this; }
/** * Adds a JOIN clause to the query * Infers the ON clause from a relation name * Uses the Propel table maps, based on the schema, to guess the related columns * Beware that the default JOIN operator is INNER JOIN, while Criteria defaults to WHERE * Examples: * <code> * $c->join('Book.Author'); * => $c->addJoin(BookTableMap::AUTHOR_ID, AuthorTableMap::ID, Criteria::INNER_JOIN); * $c->join('Book.Author', Criteria::RIGHT_JOIN); * => $c->addJoin(BookTableMap::AUTHOR_ID, AuthorTableMap::ID, Criteria::RIGHT_JOIN); * $c->join('Book.Author a', Criteria::RIGHT_JOIN); * => $c->addAlias('a', AuthorTableMap::TABLE_NAME); * => $c->addJoin(BookTableMap::AUTHOR_ID, 'a.ID', Criteria::RIGHT_JOIN); * </code> * * @param string $relation Relation to use for the join * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return $this|ModelCriteria The current object, for fluid interface */ public function join($relation, $joinType = Criteria::INNER_JOIN) { // relation looks like '$leftName.$relationName $relationAlias' list($fullName, $relationAlias) = self::getClassAndAlias($relation); if (false === strpos($fullName, '.')) { // simple relation name, refers to the current table $leftName = $this->getModelAliasOrName(); $relationName = $fullName; $previousJoin = $this->getPreviousJoin(); $tableMap = $this->getTableMap(); } else { list($leftName, $relationName) = explode('.', $fullName); $shortLeftName = self::getShortName($leftName); // find the TableMap for the left table using the $leftName if ($leftName === $this->getModelAliasOrName() || $leftName === $this->getModelShortName()) { $previousJoin = $this->getPreviousJoin(); $tableMap = $this->getTableMap(); } elseif (isset($this->joins[$leftName])) { $previousJoin = $this->joins[$leftName]; $tableMap = $previousJoin->getTableMap(); } elseif (isset($this->joins[$shortLeftName])) { $previousJoin = $this->joins[$shortLeftName]; $tableMap = $previousJoin->getTableMap(); } else { throw new PropelException('Unknown table or alias ' . $leftName); } } $leftTableAlias = isset($this->aliases[$leftName]) ? $leftName : null; // find the RelationMap in the TableMap using the $relationName if (!$tableMap->hasRelation($relationName)) { throw new UnknownRelationException(sprintf('Unknown relation %s on the %s table.', $relationName, $leftName)); } $relationMap = $tableMap->getRelation($relationName); // create a ModelJoin object for this join $join = new ModelJoin(); $join->setJoinType($joinType); if (null !== $previousJoin) { $join->setPreviousJoin($previousJoin); } $join->setRelationMap($relationMap, $leftTableAlias, $relationAlias); // add the ModelJoin to the current object if (null !== $relationAlias) { $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { $this->addJoinObject($join, $relationName); } return $this; }
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'); }
/** * @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, ', ') . ')'); }
/** * Adds a JOIN clause to the query using the RoutineRelatedByPerformanceMusicAndTimingStatisticId relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return $this|ChildPerformanceStatisticQuery The current query, for fluid interface */ public function joinRoutineRelatedByPerformanceMusicAndTimingStatisticId($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('RoutineRelatedByPerformanceMusicAndTimingStatisticId'); // create a ModelJoin object for this join $join = new ModelJoin(); $join->setJoinType($joinType); $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); if ($previousJoin = $this->getPreviousJoin()) { $join->setPreviousJoin($previousJoin); } // add the ModelJoin to the current object if ($relationAlias) { $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { $this->addJoinObject($join, 'RoutineRelatedByPerformanceMusicAndTimingStatisticId'); } return $this; }
/** * Adds a JOIN clause to the query using the КалендарьRelatedByфактическаядатаустранения relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return $this|ChildПредписанияQuery The current query, for fluid interface */ public function joinКалендарьRelatedByфактическаядатаустранения($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('КалендарьRelatedByфактическаядатаустранения'); // create a ModelJoin object for this join $join = new ModelJoin(); $join->setJoinType($joinType); $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); if ($previousJoin = $this->getPreviousJoin()) { $join->setPreviousJoin($previousJoin); } // add the ModelJoin to the current object if ($relationAlias) { $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { $this->addJoinObject($join, 'КалендарьRelatedByфактическаядатаустранения'); } return $this; }
/** * Adds a JOIN clause to the query using the Author relation. * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * @return $this|BookQuery The current query, for fluid interface */ public function joinAuthor($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { $entityMap = $this->getEntityMap(); $relationMap = $entityMap->getRelation('Author'); // create a ModelJoin object for this join $join = new ModelJoin(); $join->setJoinType($joinType); $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getEntityAlias() : null, $relationAlias); if ($previousJoin = $this->getPreviousJoin()) { $join->setPreviousJoin($previousJoin); } // add the ModelJoin to the current object if ($relationAlias) { $this->addAlias($relationAlias, $relationMap->getRightEntity()->getName()); $this->addJoinObject($join, $relationAlias); } else { $this->addJoinObject($join, 'Author'); } return $this; }
/** * Adds a JOIN clause to the query using the LocalizationRelatedByExtLanguageId relation * * @param string $relationAlias optional alias for the relation * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return $this|ChildLanguageQuery The current query, for fluid interface */ public function joinLocalizationRelatedByExtLanguageId($relationAlias = null, $joinType = Criteria::LEFT_JOIN) { $tableMap = $this->getTableMap(); $relationMap = $tableMap->getRelation('LocalizationRelatedByExtLanguageId'); // create a ModelJoin object for this join $join = new ModelJoin(); $join->setJoinType($joinType); $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); if ($previousJoin = $this->getPreviousJoin()) { $join->setPreviousJoin($previousJoin); } // add the ModelJoin to the current object if ($relationAlias) { $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); $this->addJoinObject($join, $relationAlias); } else { $this->addJoinObject($join, 'LocalizationRelatedByExtLanguageId'); } return $this; }