ruby on rails - default sort order for an activerecord model? -
this question has answer here:
- activerecord find not sorting id? 4 answers
if didn't set default_scope in model(account), , call account.first, item returned ?
here axample: account table have 5 records, account.all returns:
account.all.map{ |x| {id: x.id, name: x.name, created_at: x.created_at, updated_at:x.updated_at}} account load (0.5ms) select "accounts".* "accounts" => [{:id=>2, :name=>"hessel, kirlin , gulgowski", :created_at=>wed, 04 sep 2013 00:44:33 edt -04:00, :updated_at=>wed, 04 sep 2013 00:44:33 edt -04:00}, {:id=>3, :name=>"hessel, kirlin , gulgowski", :created_at=>wed, 04 sep 2013 00:44:34 edt -04:00, :updated_at=>wed, 04 sep 2013 00:44:34 edt -04:00}, {:id=>4, :name=>"hessel, kirlin , gulgowski", :created_at=>wed, 04 sep 2013 00:44:34 edt -04:00, :updated_at=>wed, 04 sep 2013 00:44:34 edt -04:00}, {:id=>5, :name=>"hessel, kirlin , gulgowski", :created_at=>wed, 04 sep 2013 00:44:35 edt -04:00, :updated_at=>wed, 04 sep 2013 00:44:35 edt -04:00}, {:id=>1, :name=>"eis", :created_at=>wed, 04 sep 2013 00:44:31 edt -04:00, :updated_at=>wed, 04 sep 2013 00:44:32 edt -04:00}]
account.first return record id 2, didn't set default_scope in model, why id 2 not id 1?
thanks !
update: answer(https://stackoverflow.com/a/4986620/655621)
my understanding in absence of order default order id used, not seem case in 3.2.13 @ least
2.0.0p247 :001 > book.first book load (60.0ms) select "books".* "books" limit 1
so maybe there has been code change in recent versions. version using?
Comments
Post a Comment