Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sortable behavior: changed moveRelatedObjectsToNullScope() to use alr…

…eady existing getMaxRank() method and fixed bug in shiftRank()
  • Loading branch information...
commit 4c369ba1a57683a38bad08ce3393c09742463466 1 parent 1e16f2c
@rozwell rozwell authored
View
3  generator/lib/behavior/sortable/SortableBehaviorPeerBuilderModifier.php
@@ -13,6 +13,7 @@
*
* @author François Zaninotto
* @author heltem <heltem@o2php.com>
+ * @author rozwell
* @package propel.generator.behavior.sortable
*/
class SortableBehaviorPeerBuilderModifier
@@ -350,7 +351,7 @@ public static function shiftRank(\$delta, \$first = null, \$last = null, " . ($u
\$whereCriteria->add($peerClassname::RANK_COL, \$first, Criteria::GREATER_EQUAL);
}
if (null !== \$last) {
- \$whereCriteria->add($peerClassname::RANK_COL, \$last, Criteria::LESS_EQUAL);
+ \$whereCriteria->addAnd($peerClassname::RANK_COL, \$last, Criteria::LESS_EQUAL);
}";
if ($useScope) {
$script .= "
View
20 generator/lib/behavior/sortable/SortableRelationBehavior.php
@@ -67,15 +67,8 @@ protected function getObjectMoveRelatedToNullScopeMethodName()
protected function addObjectMoveRelatedToNullScope(&$script)
{
- $database = $this->getTable()->getDatabase();
- $tableName = $database->getTablePrefix() . $this->getParameter('foreign_table');
- $peer = $this->builder->getNewStubPeerBuilder($this->getForeignTable())->getClassname();
-
- $maxSql = sprintf('SELECT MAX(%s) FROM %s WHERE %s IS NULL',
- $this->getForeignColumnForParameter('foreign_rank_column')->getName(),
- $database->getPlatform()->quoteIdentifier($tableName),
- $this->getForeignColumnForParameter('foreign_scope_column')->getFullyQualifiedName()
- );
+ $peerClass = $this->builder->getNewStubPeerBuilder($this->getForeignTable())->getClassname();
+ $queryClass = $this->builder->getNewStubQueryBuilder($this->getForeignTable())->getClassname();
$script .= "
/**
@@ -85,14 +78,11 @@ protected function addObjectMoveRelatedToNullScope(&$script)
public function {$this->getObjectMoveRelatedToNullScopeMethodName()}(PropelPDO \$con = null)
{
if (\$con === null) {
- \$con = Propel::getConnection($peer::DATABASE_NAME, Propel::CONNECTION_WRITE);
+ \$con = Propel::getConnection($peerClass::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
- \$stmt = \$con->prepare('$maxSql');
- \$stmt->execute();
- \$maxRank = (int)\$stmt->fetchColumn();
-
- $peer::shiftRank(\$maxRank, null, null, \$this->getPrimaryKey(), \$con);
+ \$maxRank = $queryClass::create()->getMaxRank(\$this->getPrimaryKey(), \$con);
+ $peerClass::shiftRank(\$maxRank, null, null, \$this->getPrimaryKey(), \$con);
}
";
View
1  test/testsuite/generator/behavior/sortable/SortableBehaviorObjectBuilderModifierWithScopeTest.php
@@ -15,6 +15,7 @@
* Tests for SortableBehavior class
*
* @author Massimiliano Arione
+ * @author rozwell
* @version $Revision$
* @package generator.behavior.sortable
*/
View
1  test/testsuite/generator/behavior/sortable/SortableBehaviorPeerBuilderModifierWithScopeTest.php
@@ -15,6 +15,7 @@
* Tests for SortableBehavior class
*
* @author Massimiliano Arione
+ * @author rozwell
* @version $Revision$
* @package generator.behavior.sortable
*/
Please sign in to comment.
Something went wrong with that request. Please try again.