diff --git a/src/Propel/Runtime/ActiveQuery/Join.php b/src/Propel/Runtime/ActiveQuery/Join.php index 632da3efc4..74996a1cb0 100644 --- a/src/Propel/Runtime/ActiveQuery/Join.php +++ b/src/Propel/Runtime/ActiveQuery/Join.php @@ -127,6 +127,7 @@ public function addCondition($left, $right, $operator = self::EQUAL) * @param array $lefts The left columns of the join condition * @param array $rights The right columns of the join condition * @param array $operators The comparison operators of the join condition, default Join::EQUAL + * @throws \Propel\Runtime\Exception\LogicException */ public function addConditions($lefts, $rights, $operators = array()) { @@ -208,6 +209,7 @@ public function addOperator($operator = null) } /** + * @param int $index * @return string[] the comparison operator for the join condition */ public function getOperator($index = 0) @@ -306,6 +308,10 @@ public function getLeftColumns() return $columns; } + /** + * @param string $leftTableName + * @return $this + */ public function setLeftTableName($leftTableName) { $this->leftTableName = $leftTableName; @@ -313,11 +319,18 @@ public function setLeftTableName($leftTableName) return $this; } + /** + * @return null|string + */ public function getLeftTableName() { return $this->leftTableName; } + /** + * @param string $leftTableAlias + * @return $this + */ public function setLeftTableAlias($leftTableAlias) { $this->leftTableAlias = $leftTableAlias; @@ -325,21 +338,33 @@ public function setLeftTableAlias($leftTableAlias) return $this; } + /** + * @return null|string + */ public function getLeftTableAlias() { return $this->leftTableAlias; } + /** + * @return bool + */ public function hasLeftTableAlias() { return null !== $this->leftTableAlias; } + /** + * @return null|string + */ public function getLeftTableAliasOrName() { return $this->leftTableAlias ? $this->leftTableAlias : $this->leftTableName; } + /** + * @return string + */ public function getLeftTableWithAlias() { return $this->leftTableAlias ? $this->leftTableName . ' ' . $this->leftTableAlias : $this->leftTableName; @@ -407,6 +432,10 @@ public function getRightColumns() return $columns; } + /** + * @param string $rightTableName + * @return $this + */ public function setRightTableName($rightTableName) { $this->rightTableName = $rightTableName; @@ -414,11 +443,18 @@ public function setRightTableName($rightTableName) return $this; } + /** + * @return null|string + */ public function getRightTableName() { return $this->rightTableName; } + /** + * @param string $rightTableAlias + * @return $this + */ public function setRightTableAlias($rightTableAlias) { $this->rightTableAlias = $rightTableAlias; @@ -426,21 +462,33 @@ public function setRightTableAlias($rightTableAlias) return $this; } + /** + * @return null|string + */ public function getRightTableAlias() { return $this->rightTableAlias; } + /** + * @return bool + */ public function hasRightTableAlias() { return null !== $this->rightTableAlias; } + /** + * @return null|string + */ public function getRightTableAliasOrName() { return $this->rightTableAlias ? $this->rightTableAlias : $this->rightTableName; } + /** + * @return string + */ public function getRightTableWithAlias() { return $this->rightTableAlias ? $this->rightTableName . ' ' . $this->rightTableAlias : $this->rightTableName; @@ -553,12 +601,20 @@ public function getClause(&$params) ); } + /** + * @param null|Join $join + * @return bool + */ public function equals($join) { + $parametersOfThisClauses = array(); + $parametersOfJoinClauses = array(); + return null !== $join && $join instanceof Join - && $this->joinType === $join->getJoinType() + && $this->getJoinType() === $join->getJoinType() && $this->getConditions() == $join->getConditions() + && $this->getClause($parametersOfThisClauses) == $join->getClause($parametersOfJoinClauses) ; } @@ -574,6 +630,9 @@ public function toString() return $this->getClause($params); } + /** + * @return string + */ public function __toString() { return $this->toString(); diff --git a/src/Propel/Runtime/ActiveQuery/PropelQuery.php b/src/Propel/Runtime/ActiveQuery/PropelQuery.php index c021e5af69..64af0d3aae 100644 --- a/src/Propel/Runtime/ActiveQuery/PropelQuery.php +++ b/src/Propel/Runtime/ActiveQuery/PropelQuery.php @@ -19,6 +19,11 @@ */ class PropelQuery { + /** + * @param $queryClassAndAlias + * @return ModelCriteria + * @throws \Propel\Runtime\Exception\ClassNotFoundException + */ public static function from($queryClassAndAlias) { list($class, $alias) = ModelCriteria::getClassAndAlias($queryClassAndAlias); diff --git a/tests/Propel/Tests/Runtime/ActiveQuery/JoinTest.php b/tests/Propel/Tests/Runtime/ActiveQuery/JoinTest.php index cdc52ca9b4..02939389a0 100644 --- a/tests/Propel/Tests/Runtime/ActiveQuery/JoinTest.php +++ b/tests/Propel/Tests/Runtime/ActiveQuery/JoinTest.php @@ -180,4 +180,24 @@ public function testCountConditions() $this->assertEquals(2, $j->countConditions()); } + public function testEquality() + { + $j1 = new Join('foo', 'bar', 'INNER JOIN'); + $this->assertFalse($j1->equals(null), 'Join and null is not equal'); + + $j2 = new Join('foo', 'bar', 'LEFT JOIN'); + $this->assertFalse($j1->equals($j2), 'INNER JOIN and LEFT JOIN are not equal'); + + $j3 = new Join('foo', 'bar', 'INNER JOIN'); + $j3->addCondition('baz.foo', 'baz.bar'); + $this->assertFalse($j1->equals($j3), 'Joins with differend conditionsare not equal'); + + $j4 = new Join('foo', 'bar', 'INNER JOIN'); + $j4->addExplicitCondition('book', 'AUTHOR_ID', null, 'author', 'ID', 'a', Join::EQUAL); + $this->assertFalse($j1->equals($j4), 'Joins with differend clauses not equal'); + + $j5 = new Join('foo', 'bar'); + $j6 = new Join('foo', 'bar'); + $this->assertTrue($j5->equals($j6), 'Joins without specified join type should be equal as they fallback to default join type'); + } }