Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

This project is archived and is in readonly mode.

default_scope doesn't work with has_many << (insertion)

#2008

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

Reported by nachocab (at gmail) · February 18th, 2009 @ 06:22 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. nachocab (at gmail)
  2. Paweł Kondzior
    Paweł Kondzior

    Isn't this because << is adding to db and to local array that contains cached data ?

    After h.reload, h.rooms should be ordered

    February 21st, 2009 @ 02:01 AM

  3. nachocab (at gmail)
    nachocab (at gmail)
    • 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.

    February 21st, 2009 @ 08:27 AM

  4. DHH
    DHH
    • State changed from new to invalid

    February 21st, 2009 @ 08:34 AM