The bug is in line 138, function afterdelete(). TO fix it, we must change
from

 $action = array($this->settings['field'] => $this->settings['field'] . ' -
1');
to
 $action = array($this->settings['field'] => '`'.$this->settings['field'] .
'` - 1');

Thanks!

mig_akira wrote:
> 
> Hello everyone.
> 
> I'm using this behavior:
> http://bakery.cakephp.org/articles/view/orderedbehavior-2-1
> 
> to ordenate pages in my site. 
> 
> But the thing is, when I delete a page, the order_display of all other
> pages does not change automatically. For example, if I have 5 pages, and
> delete the page with order_display number 3, I'll have the following
> order_display: 1, 2, 4, 5 and not 1,2,3,4, which would be correct.
> 
> I believe it must be a bug in the afterdelete filter in the behavior, but
> I can't understand wit, since I'm new to cakephp. Could you people check
> it out please?
> 
> Here's the code:
> 
>       public function beforeDelete(&$Model) {
> 
>               $Model->read();
> 
>               $highest = $this->_highest($Model);
> 
>               if (!empty($Model->data) &&
> ($Model->data[$Model->alias][$Model->primaryKey] ==
> $highest[$Model->alias][$Model->primaryKey])) {
> 
>                       $Model->data = null;
> 
>               }
> 
>       }
> 
>       public function afterDelete(&$Model) {
> 
>               if ($Model->data) {
> 
>                       // What was the weight of the deleted model?            
> 
>                       $old_weight = 
> $Model->data[$Model->alias][$this->settings['field']];
> 
>                       // update the weight of all models of higher weight by
> 
>                       
> 
> 
> 
>                       $action = array($this->settings['field'] => 
> $this->settings['field'] .
> ' - 1');
> 
>                       $conditions = array(
> 
>                                       $Model->alias . '.' . 
> $this->settings['field'] . ' >' =>
> $old_weight);
> 
>                       if ($this->settings['foreign_key']) {
> 
>                               $conditions[$Model->alias . '.' . 
> $this->settings['foreign_key']] =
> $Model->data[$Model->alias][$this->settings['foreign_key']];
> 
>                       }
> 
>                       // decreasing them by 1
> 
>                       return $Model->updateAll($action, $conditions);
> 
>               }
> 
>               return true;
> 
>       }
> 
> 
> I'm using a simple $this->Page->del($id) in the controller to delete the
> pages.
> 
> Thanks a lot!!
> 

-- 
View this message in context: 
http://www.nabble.com/orderedBehavior-2.1.2---Bug-in-afterdelete-function--tp23907768p23923573.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to