Ruby on Rails
Saturday, July 6, 2013
Hi,
So Model.last produces the following sql:
SELECT * FROM models ORDER BY models.id DESC LIMIT 1
That said, I've no idea why you only get a part of the records back.
Were you able to validates all those numbers directly on the DB?
Regards
Geoffroy
Op vrijdag 5 juli 2013 23:16:14 UTC+2 schreef Colin Law het volgende:
On 5 July 2013 18:06, zip py <li...@ruby-forum.com> wrote:
> Hi
>
> I have a Rail 4 with Postrgesql 9.1 setup that is working fine, apart
> from I just ran into an issue.
>
> Lets say I have a model called MyModel that has 150 records.
>
> If in IRB I try:
>
>> test = MyModel.all
>
> Only 138 records are returned.
How do you know?
>
> If I now try:
>
>> lastRecord = test.last
>
> The record I get has an ID of 138
If you have not specified an order clause then the order you get the
records in is undefined, so the last record is not necessarily the
highest id.
>
> And yet if I try:
>
>> test.count
>
> It returns the correct value - 50!
I presume you mean 150
Colin
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/56352800-fcf0-4ad1-80b1-a1bcb75290f2%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment