On Tue, Aug 18, 2009 at 5:01 PM, Ben Johnson<[email protected]> wrote: > > I just switched to Postgres and some of my tests are failing. It seems > that Postgres defaults by ordering data by ID DESC, whereas MySQL > defaults to ordering by ID ASC. > > What is the best practice for handling this? Is there a setting in > Postgres you can change? Should I be explicitly specifying the order of > my data in my queries? > > In various places throughout my application I am doing things like: > > User.first > > This obviously is not good with the order of the data is not consistent. > I also feel like the first User should return the first user, not the > last one created.
The Rails tests use explicit ordering to work around this discrepancy. User.first without an ordering is technically undefined. It could be any row. Since you're usually doing account.users.first, you could :order => 'id asc' on the has_many. jeremy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

