This project is archived and is in readonly mode.
default_scope doesn't work with has_many << (insertion)
Reported by nachocab (at gmail) | February 18th, 2009 @ 06:22 PM | in 2.x
When adding items through the '<<' operator to a has_many relationship the default scoping with DESC ordering has no effect, and results are returned in the the order they were added. http://gist.github.com/66456
Comments and changes to this ticket
-
nachocab (at gmail) February 19th, 2009 @ 06:17 AM
I uploaded a sample app with a failing test: http://github.com/nachocab/defau...
-
Paweł Kondzior February 21st, 2009 @ 02:01 AM
Isn't this because << is adding to db and to local array that contains cached data ?
After h.reload, h.rooms should be ordered
-
nachocab (at gmail) February 21st, 2009 @ 08:27 AM
- Assigned user cleared.
You're right Paweł. I hadn't realized it was saving it into a local array until the House record was created. No need to reload, really, just doing House.create and then adding both rooms returns the records with default_scope. Thanks for clearing it up. You can cancel this ticket.
-
DHH February 21st, 2009 @ 08:34 AM
- State changed from new to invalid
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>