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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to