2012-04-09 30 views
0

我正在cakephp中開發一個應用程序。我需要獲取cakephp中使用updateAll()函數更新的所有行的id。任何建議將不勝感激。感謝名單..如何獲取cakephp中updateAll()函數更新的行的ID?

這是我應該在我的應用程序模型

class AppModel extends Model { 

    var $infos = array(); 

    function updateAll($fields, $conditions = true) { 
     $this->$infos = $this->find('all', array('conditions' => $conditions)); 
     $return = parent::updateAll($fields, $conditions); 
     $this->afterUpdateAll(); 
     return $return; 
    } 


    function afterUpdateAll(){ 
     foreach ($this->$infos as $info) { 
      //do something 
     } 
    } 

} 

做將這項工作..?

回答

1

您必須發出一個find,通過與您傳遞給updateAll相同的條件。

如果更新操作更改任何條件下使用的列的數據,你應該調用updateAll之前使用find

+0

編輯了我的疑問,請查看 – Vineet 2012-04-09 13:56:09

+0

@ vin.it,對你貼出來,看到我更新的答案代碼一個陷阱。 – bfavaretto 2012-04-09 14:01:40

+0

是啊很酷,很好的觀察..編輯我的代碼,只是檢查它.. – Vineet 2012-04-09 14:06:47

0

如果UPDATE的uncial行 - 你可能只是SELECT他們後再次UPDATE

+0

已編輯我的問題,請檢查 – Vineet 2012-04-09 13:55:50