It's true that relations as sets that to feel a whole lot like arrays, but
the fact that query conditions are composable (and no one is arguing that
they shouldn't be) implies that other operations should also be composable.
To have conditions be composable and orderings not would be an impedance
mismatch that would violate the POLS actually.

As far as the default_scope issues, I personally believe that default
orderings on either default_scope or associations should be considered
harmful and are generally a hack fix for view sorting that violates
separation of concerns.

If you want a specific ordering and you're using a pre-made relation (like
an association), perhaps you should be using reorder.

I'm totally in favor of clarifying docs however.


On Tue, Apr 15, 2014 at 11:12 AM, Cameron Martin <[email protected]
> wrote:

> Relational algebra deals with sets, and sets are collections. Standard
> relational algebra doesn't define an order by operator, but if you want
> define an order between the elements in the set, you're getting towards
> something which behaves quite a lot like an array.
>
> James, I see your point about api-breaking changes. How about updating the
> guide to notify people of this behaviour in case they do not expect it, and
> let them know that the reorder method exists too?
>
> On Monday, 14 April 2014 23:19:18 UTC+1, Cameron Martin wrote:
>>
>> When chaining calls to order on an ActiveRecord association, the result
>> is a composition of the two order calls. I believe this breaks the
>> principle of least surprise, since calling sort/order on a collection never
>> behaves like this anywhere else (for example with Array#sort). Any
>> subsequent calls to order should re-order the collection in the way you
>> specify.
>>
>> I can't imagine any situations where you would chain calls to order and
>> want/expect this behaviour, but I can think of many situations where it can
>> lead to unexpected results (for example when using default_scope for
>> ordering).
>>
>> I propose that reorder be renamed to order, and order be renamed to
>> append_order or something similar.
>>
>> Thoughts?
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to