Reputation: 21
I have a query like:
Update `pools` set status='2' where `pid`='1' and `uid`='2'
How do I convert this query in cakephp? i.e. I want to pass that AND condition in query which should update row containing pid='1' and uid='2'.
Upvotes: 2
Views: 22588
Reputation: 27364
UPDATEALL
is all you need.
$this->Pool->updateAll(array('status'=>2), array('Pool.pid'=>1,'Pool.uid' => 2));
For more documentation.
If you already have id for the row which you want to update then no need to use update cakephp is very much clever enough to understand it.
For example.
if you have Pool.id
which is row of record then.
$this->data['Pool']['id'] = $pool_id;
$this->data['Pool']['uid'] = $pool_uid;
$this->data['Pool']['other_data'] = $pool_otherData;
$this->Pool->save($this->data['Pool']);
above will automatically save $pool_id row.
Upvotes: 5
Reputation: 1107
I guess this may work...Just try...
$this->Pool->updateAll(array('status'=>2), array('AND' => array('Pool.pid'=>1,'Pool.uid' => 2)));
Upvotes: 0