Well this may be a question with a simple answer but I've been searching and couldn't find how to do this.
I have the models: sales and follow. The table follow has an id, an user_id and sale_id. What I wan't to do is: on the sales_controller I need to find one follow record that has the user_id that is Authenticated and the sale_id that is passed as parameter.
So here is what I've tried:
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();
In attempt #3 e #4 '$result' does return the value i was expecting, but delete doesn't work.
But none of these attempts worked out.
Anyone can help?
Thanks.