I have a question about peoples opinions about how nested named_scopes should handle :order options. What are your opinions about the correct behavior for the following chained named_scopes? Take the model: class Developer < ActiveRecord::Base named_scope :by_last_name, :order => ''last_name'' named_scope :by_first_name, :order => ''first_name'' end In which order should the following calls return the models? 1) Developer.by_last_name 2) Developer.by_last_name.by_first_name In case 2) I think that the order should be "last_name, "first_name". This is not the current edge Rails behavior. Now change the model to: class Developer < ActiveRecord::Base default_scope :order => ''salary DESC'' named_scope :by_last_name, :order => ''last_name'' named_scope :by_first_name, :order => ''first_name'' end In which order should the following calls return the models? 1) Developer.find(:all) 2) Developer.by_last_name 3) Developer.by_last_name.by_first_name In case 2) I think that the order should be "last_name". This is the current edge Rails behavior. In case 3) I think the order should be "last_name, first_name". Does this match peoples expectations and usage of named_scope and default_scope? If so, I can submit a patch to allow :order options to be merged. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 10, 2009, at 8:32 PM, Erik Andrejko wrote:> > I have a question about peoples opinions about how nested named_scopes > should handle :order options. > > What are your opinions about the correct behavior for the following > chained named_scopes?I guess merging order options seems like a good idea but I wouldn''t recommend hacking it into with_scope in its current state. Pratik said that we wanted to clean up some of the scoping code after 2.3.1 is released, maybe it''s a good idea to tackle order merging during those changes? It''s probably a good idea to create a ticket and submit some testcases, that way we don''t forget (: Manfred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On 10 Mar 2009, at 19:32, Erik Andrejko wrote:> > I have a question about peoples opinions about how nested named_scopes > should handle :order options. > > What are your opinions about the correct behavior for the following > chained named_scopes? > > Take the model: > > class Developer < ActiveRecord::Base > named_scope :by_last_name, :order => ''last_name'' > named_scope :by_first_name, :order => ''first_name'' > end > > > In which order should the following calls return the models? > > 1) Developer.by_last_name > 2) Developer.by_last_name.by_first_name > > In case 2) I think that the order should be "last_name, "first_name". > This is not the current edge Rails behavior. > > Now change the model to: > > class Developer < ActiveRecord::Base > default_scope :order => ''salary DESC'' > named_scope :by_last_name, :order => ''last_name'' > named_scope :by_first_name, :order => ''first_name'' > end > > In which order should the following calls return the models? > > 1) Developer.find(:all) > 2) Developer.by_last_name > 3) Developer.by_last_name.by_first_name > > In case 2) I think that the order should be "last_name". This is the > current edge Rails behavior. In case 3) I think the order should be > "last_name, first_name". > > Does this match peoples expectations and usage of named_scope and > default_scope? If so, I can submit a patch to allow :order options to > be merged. >This looks good to me. I''ve been bitten once before by named scopes not merging the order option. Tekin Suleyman Ruby on Rails Developer +44 (0) 161 408 8868 +44 (0) 7968 355 460 http://tekin.co.uk --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks everyone for your input. There is now a ticket: http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2253-named_scope-and-nested-order-clauses Erik --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---