This project is archived and is in readonly mode.

#2346 open
Alexander Podgorbunsky

named_scope doesn't override default_scope's :order key

Reported by Alexander Podgorbunsky | March 26th, 2009 @ 01:04 PM | in 2.3.10

There's a problem of not overriding deafult_scope's keys that don't merge (:order for instance) by same keys of named_scopes


class Post
  default_scope :order => 'posts.created_at asc'
  named_scope :recent, :order => 'posts.created_at desc'
end

Post.recent # sorts posts in ascending order

This behavior appeared as a result of resolving #1960

Here's the the patch to fix it Patch also fixes test that was broken too (see comments on #1960)

Added code checks if scoping that was current on creation of Scope object is in scoped_methods stack on execution of scope, and if so - doesn't apply it second time (as it's been already implicitly accounted for during merging named scope's scoping with current_scoped_methods). This eliminates a problem of overriding keys of named scope by default scope

Comments and changes to this ticket

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>

Attachments

Referenced by

Pages