They're not the same, right.
I mean, it depends on what you need. The real ID or just an amount of
records.

But If task is to get random record you will

Company.all[rand(Company.count)] but not
Company.all[rand(Company.last.id)]

On Mon, Apr 19, 2010 at 11:29 PM, Hassan Schroeder <
[email protected]> wrote:

> On Mon, Apr 19, 2010 at 9:03 AM, Vladimir Rybas <[email protected]>
> wrote:
> > To find the last id of MyModel you could do
> > MyModel.last.id
> > even souds like it should )
> > But it's not what you really want for upper bound. In your case
> > MyModel.count(:all) or just MyModel.count
> > will fit better
>
> ? That's not the same. If I have a DB that assigns IDs sequentially,
> and I've created 5 instances, the last id will be 5.
>
> If I subsequently destroy an instance, e.g. id == 1, the last id is still
> 5, but the count is 4.
>
> --
> Hassan Schroeder ------------------------ [email protected]
> twitter: @hassan
>
> --
> 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]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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