Index: /plugins/csDoctrineActAsSortablePlugin/branches/1.4/lib/template/Sortable.php =================================================================== --- /plugins/csDoctrineActAsSortablePlugin/branches/1.4/lib/template/Sortable.php (revision 30158) +++ /plugins/csDoctrineActAsSortablePlugin/branches/1.4/lib/template/Sortable.php (revision 30938) @@ -2,5 +2,5 @@ /** - * Easily create a slug for each record based on a specified set of fields + * Easily adds sorting functionality to a record. * * @package csDoctrineSortablePlugin @@ -199,5 +199,6 @@ ->set($this->_options['name'], $this->_options['name'] . ' - 1') ->where($this->_options['name'] . ' > ?', $position) - ->andWhere($this->_options['name'] . ' <= ?', $newPosition); + ->andWhere($this->_options['name'] . ' <= ?', $newPosition) + ->orderBy($this->_options['name'] . ' ASC'); foreach($this->_options['uniqueBy'] as $field) @@ -346,5 +347,5 @@ * Get the final position of a model * - * @return $position + * @return int $position */ public function getFinalPosition() @@ -368,7 +369,8 @@ } - $finalPosition = (int) $q->fetchOne(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR); - - return $finalPosition; + $last = $q->limit(1)->fetchOne(); + $finalPosition = $last ? $last->get($this->_options['name']) : 0; + + return (int)$finalPosition; } }