I have a multi-tenant system (by subdomain) and each subdomain needs
their own perspective on an incrementing check number. This does the
job:


  before_validation(:on => :create) do
    Check.transaction do
      self.number = (Check.maximum(:number) || 0) + 1
    end
  end



On Jun 17, 1:07 am, Mauro <[email protected]> wrote:
> On 16 June 2011 22:12, Rob Biedenharn <[email protected]> wrote:
>
> > Does everyone here realize that the 'id' is typically tied to a database
> > column that is set to auto-increment (in whatever fashion the underlying
> > database supports) for the primary key?
>
> > Also, if you ever delete a record, the .count will decrease and you'll get a
> > duplicate for the next created record.
>
> I had not thought about this.

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to