Thursday, June 25, 2009

Re: Simple SQL UPDATE question

Good point. The updateAll method probably does load of uneccessary
left joins... I'll probably switch to a custom query as since it's an
update, there's no caching involved, so no speed to be gained by using
Cake's built in methods.

On Jun 24, 9:27 pm, Miles J <mileswjohn...@gmail.com> wrote:
> You could write it like that, but a custom is just simpler and
> faster :p
>
> On Jun 24, 12:15 pm, Rangi <rangi...@gmail.com> wrote:
>
> > Thanks for all the replies everyone.
>
> > I think I'm going to go with the updateAll method:
>
> > $this->Product->updateAll(array('Product.vote'=>'Product.vote+1'),
> > array('Product.id'=>40));
>
> > On Jun 24, 5:07 pm, brian <bally.z...@gmail.com> wrote:
>
> > > On Wed, Jun 24, 2009 at 3:35 AM, Rangi<rangi...@gmail.com> wrote:
>
> > > > Hello,
>
> > > > I've searched the manual and this group for an answer to this but
> > > > can't find anything, so wondering if anyone can help.
>
> > > > I'd like to do a query like this:
>
> > > > UPDATE product SET num_ratings = num_ratings + 1;
>
> > > > In CakePHP I can't figure out how to do it in less than 2 queries
> > > > (load record to look up num_ratings, increment num_ratings in php,
> > > > save record).
>
> > > > Should I just use a custom query for this?
>
> > > See here:http://teknoid.wordpress.com/2008/05/22/incrementing-a-field-in-cakephp/
>
> > > Also, check out IncrementBehavior
>
> > >http://bakery.cakephp.org/articles/view/increment-behavior
--~--~---------~--~----~------------~-------~--~----~
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: