Btw, that could also resolve the "how to combine `default_scope`s issue, if
that's something that is still desired.

default_scope where( :foo => 1 )


And then:

default_scope where( :foo => 2 ) # effectively negates previous default
scope
default_scope and( :foo => 2 ) # same as above
default_scope or( :foo => 2 ) # merges with original


All nice and explicit.

AND:

User.or( :foo => 2 )


...would also combine with any existing default_scope, whereas:

User.where( :foo => 2 )


Would AND it and therefore negate the default scope.

On Wed, Feb 16, 2011 at 10:22 AM, Jason King <j...@handle.it> wrote:

> Just want to get this onto the table, "what most people expect" is not the
> only measure of a good API choice.
>
> To specifically answer Aaron's question, for #4598, I think the fix for
> that would be for subsequent `default_scope`s to just overwrite previous
> ones entirely.  Not to merge with them.
>
> For the broader question which seems to be what this thread is about, ie.
> what to do with: User.where(:foo => 1).where(:foo => 2) how about adding
> alias `and` as an alias for `where`, and adding `or` as an alias for "where
> that does ORs".  So the syntax could be:
>
> User.where(:foo => 1).and(:foo => 2)
>
>
> And:
>
> User.where(:foo => 1).or(:foo => 2)
>
>
> I'm sure I don't need to state what SQL each of those turn into (the real
> test for a good API :)
>
> On Wed, Feb 16, 2011 at 9:10 AM, Robert Pankowecki <
> robert.pankowe...@gmail.com> wrote:
>
>> On Wed, Feb 16, 2011 at 5:59 PM, Aaron Patterson
>> <aa...@tenderlovemaking.com> wrote:
>> > The intentional change fixes this bug:
>> >
>> >
>> https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4598-default_scope-treats-hashes-and-relations-inconsistently-when-overwriting
>> >
>> > If there is a different way to fix that ticket, I'm happy to apply
>> > patches.
>>
>> The different way is to make both cases return an empty array. David
>> (who created the ticket) expects something different but I am not sure
>> that this is what most people expect.
>>
>> Could we provide a different method for such behavior as expected by David
>> ?
>>
>> Robert Pankowecki
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/rubyonrails-core?hl=en.
>>
>>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to