This project is archived and is in readonly mode.
named_scope and nested order clauses
Reported by Erik Andrejko | March 16th, 2009 @ 01:35 PM | in 3.x
named_scope
currently has some unexpected behavior
when nesting :order
clauses. This problem also occurs
in the underlying with_scope
implementation.
This test does not pass:
def test_scoping_with_multiple_order
expected = Monk.find(:all, :order => "birth_year, first_name").map{|m| m.full_name}
options = {:order => "birth_year"}
Monk.with_scope(:find => options) do
assert_equal expected, Monk.find(:all, :order => "first_name").map{|m| m.full_name}
end
end
This test passes, and has the expected behavior:
def test_single_named_scope_overrides_default_scope_order
expected = Monk.find(:all, :order => "last_name asc").collect {|m| m.id}
received = Monk.by_last_name.collect {|m| m.id}
assert_equal expected, received
end
This test does not pass:
def test_nested_scopes_orders_combined
expected = Monk.find(:all, :order => "last_name asc, first_name asc").collect {|m| m.last_name + ", " + m.first_name}
received = Monk.by_last_name.by_first_name.collect {|m| m.last_name + ", " + m.first_name}
assert_equal expected, received
end
I have included a patch containing these tests and the
Monk
model.
For more discussion see this conversation on Rails Core.
Comments and changes to this ticket
-
Peter Wagenet March 19th, 2009 @ 02:05 PM
This may be fixed in my patch here: http://rails.lighthouseapp.com/p...
-
Nicole April 7th, 2009 @ 07:48 PM
- no changes were found...
-
Maurício Linhares May 28th, 2009 @ 10:20 PM
On Rails 2.3.2 this isn't fixed yet.
+1
Would be really nice to have this fixed.
if key == :conditions && merge if params[key].is_a?(Hash) && hash[method][key].is_a?(Hash) hash[method][key] = merge_conditions(hash[method][key].deep_merge(params[key])) else hash[method][key] = merge_conditions(params[key], hash[method][key]) end elsif key == :include && merge hash[method][key] = merge_includes(hash[method][key], params[key]).uniq elsif key == :joins && merge hash[method][key] = merge_joins(params[key], hash[method][key]) elsif key == :order && merge hash[method][key] = [params[key], hash[method][key]].join(' , ') else hash[method][key] = hash[method][key] || params[key] end
-
Erik Andrejko June 7th, 2009 @ 12:23 AM
A patch that includes tests for the desired behavior is attached.
-
Jon June 25th, 2009 @ 09:50 PM
- Assigned user set to Pratik
Still having this problem as you can see in this gist: http://gist.github.com/136140
Probably related to this ticket: #2346
-
Emilio Tagua July 7th, 2009 @ 09:43 PM
You may want to take a look to this ticket/patch, i think that solves this problem:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets...
-
csnk May 18th, 2011 @ 08:30 AM
We are the professional clothing manufacturer and clothing supplier, so we manufacture kinds of custom clothing manufacturer. welcome you to come to our china clothing manufacturer and clothing factory.
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>
People watching this ticket
Attachments
Tags
Referenced by
- 2346 named_scope doesn't override default_scope's :order key Probably related to ticket #2253
- 2346 named_scope doesn't override default_scope's :order key Not working for me as well. Following a couple of the lin...