我有型號:銷售和關注。表格後面有一個id,一個user_id和sale_id。 我想要做的是:在sales_controller上,我需要找到一個具有已驗證的user_id和作爲參數傳遞的sale_id的跟蹤記錄。刪除不同型號的記錄
所以這是我試過:
嘗試1,
App::import('model','Follow');
$follow = new Follow();
$follow->user_id = $this->Auth->user('id');
$follow->sale_id = $id;
$follow->delete();
嘗試2,
App::import('model','Follow');
$follow = new Follow();
$follow->delete(array('Follow.user_id'=>$this->Auth->user('id'), 'Follow.sale_id'=>$id));
嘗試3,
App::import('model','Follow');
$follow = new Follow();
$result = $follow->find('first',array('conditions'=>array('Follow.user_id'=>$this->Auth->user('id'), 'Follow.sale_id'=>$id)));
$result->delete()
嘗試4,
var $uses = array('Sale', 'Follow');
(...)
$result = $this->Follow->find('first',array('conditions'=>array('Follow.user_id'=>$this->Auth->user('id'), 'Follow.sale_id'=>$id)));
$result->delete();
在嘗試3和4 $result
確實返回我期待的值,但刪除不起作用。
但是這些嘗試都沒有解決。
難道你不能首先獲取符合條件的記錄(而不是創建一個新的'Follow'對象),然後在其上調用'delete()'?不是最有效的方法,但這就是Active Record似乎工作的方式... – Franz 2009-12-22 14:51:35
但是,我可以做$ this->遵循我做的應用程序::導入?我嘗試做的發現:$ this-> Follow-> find('first',array('conditions'=> array('Follow.user_id'=> $ this-> Auth-> user('id')) ,'Follow.sale_id'=> $ id)))但它沒有返回任何結果...我在這裏做錯了什麼? – Canastro 2009-12-22 15:19:07