mysql - Rails with Postgres data is returned out of order -
i've transitioned app mysql postgres. previously, request .all returned rows in id order. on postgres rows returned out of order. likewise,
person.first
used homecoming record id 1, returns record.
if add together order clause this:
person.order("id").first
the query succeeds , returns first row. expected behaviour?
this post answers question:
i don't think ordering id guaranteed default, since believe it's database how non-ordered query gets returned. can create ordered defining default scope @ top of model so:
default_scope order('id asc')
then calling model.all equivalent calling model.order('id asc').
mysql ruby-on-rails postgresql rails-activerecord
No comments:
Post a Comment