According to this, ActiveRecord first generates the SQL:
SELECT * FROM clients LIMIT 1
whereas ActiveRecord last generates the SQL:
SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
The behavior on first is not correct, according to my opinion, whereas on last it is. If you do not specify the ordering, simple SELECT returns in arbitrary or unpredictable order. Hence, first does not guarrantee to return the same record always (if not the record with minimum id).
Does anybody have a clue, why does Rails ActiveRecord work like that?
Thanks in advance
Panayotis
Since I didn’t get any answer on this post, I tried to find the answer from other people on other forums. I believe that either ActiveRecord (or mysql gem) has a bug. Rick James says that if we want to get the minimum id, we should use order by with limit. Here is his answer:
http://forums.mysql.com/read.php?22,530328,530514#msg-530514