Saturday, November 27, 2010

Re: conversion of mysql query to cakephp query

Try:

$this->User->saveField(array('User.balance'=>'User.balance-5'), array('User.id'=>1));

Jeremy Burns
Class Outfit

jeremyburns@classoutfit.com
http://www.classoutfit.com

On 27 Nov 2010, at 11:08, djogo wrote:

> Miles, that would require SELECTing the value of balance beforehand.
>
> I [1] thought that
>
> $model->save( array('id'=>'1','balance'=>'-!balance+5') );
>
> would work, but it didn't in my cake1.3.3
>
> [1] http://cakebaker.42dh.com/2007/05/04/how-to-use-sql-functions-in-conditions/
>
>
> On 26 nov, 23:29, Miles J <mileswjohn...@gmail.com> wrote:
>> $this->id = 1;
>> $this->save(array('balance' => $balance - 5));
>>
>> On Nov 26, 12:58 am, Vivi Vivi <vivianbog...@gmail.com> wrote:
>>
>>
>>
>>> http://book.cakephp.org/view/1031/Saving-Your-Data
>>
>>> On Fri, Nov 26, 2010 at 10:19 AM, Biplab Subedi <bipla...@gmail.com> wrote:
>>>> Help me in converting this mysql query to cakephp query
>>
>>>> $query="UPDATE tbl_user SET balance=(balance-5) WHERE id='1";
>>
>>>> Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others
>>>> with their CakePHP related questions.
>>
>>>> You received this message because you are subscribed to the Google Groups
>>>> "CakePHP" group.
>>>> To post to this group, send email to cake-php@googlegroups.com
>>>> To unsubscribe from this group, send email to
>>>> cake-php+unsubscribe@googlegroups.com<cake-php%2Bunsubscribe@googlegroups.c om>For more options, visit this group at
>>>> http://groups.google.com/group/cake-php?hl=en
>>
>>> --
>>> Vivihttp://photos.vr-3d.net
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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

No comments: