Re: Auto Increment A Field
Usually I let the counter cache do this kind of things, my apps are
not so famous that I will run into problems due to high CPU ussage,
and nowadays disk space is really cheap. For instance I would create a
'votes' table and model, and store there datetime, user id, ip address
and other details of the voter
On 13 mar, 23:47, euromark <dereurom...@googlemail.com> wrote:
> nice catch :)
> i guess thats true
>
> additionally, updateAll() doesnt trigger any callbacks like
> beforeSave() or afterSave().
> probably a good thing in this case, as well
>
> On 13 Mrz., 23:06, Ryan Schmidt <google-2...@ryandesign.com> wrote:
>
> > Nick, that code has a race condition. Two different users looking at the page at the same time could cause the count to be incremented by only one total, when you want the count to be incremented by one for each user.
>
> > The method Krissy showed is atomic and does not have this problem.
>
> > On Mar 12, 2011, at 11:28, nurvzy wrote:
>
> > > $this->Product->id = 40;
> > > $this->Product->saveField('vote', $this->Product->field('vote') + 1);
>
> > > Nick
>
> > > On Mar 12, 9:36 am, Krissy Masters wrote:
> > >> $this->Product->updateAll(array('Product.vote'=>'Product.vote+1'),
> > >> array('Product.id'=>40));
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
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
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home