On 08.02.2012, at 13:39, Colin Law wrote:

> On 8 February 2012 07:12, Bob Smith <bsm...@gmail.com> wrote:
>> I need a way to set a counter that will show how many of the model
>> have been created and put this in each instance. This will allow me to
>> use the record number as an input to another field before id is set.
>> After things are settled, the real id number can be substituted for
>> the counter.
> 
> If you do that and two users come along at the same time and make new
> objects then they will both get the same number.  Can you not just use
> a before_save filter to set the field?  If you think not can you
> explain what you are trying to do (and why) in more detail as there is
> almost certainly a better solution.

I think actually he asked about something counter-caching solution for 
stand-alone model/table. Good question, for the best approach it has to be 
realized on a database level. The second approach is to build additional 
caching table to keep counter values for anything you want. The last one is not 
so elegant.

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

Reply via email to