> On 30 Aug 2018, at 12:31, Piotr Szmielew <p.szmie...@ava.waw.pl> wrote:
> 
> Why not simply use default scope with ordering? I believe it would be 
> equivalent.
> 
> I.e.:
> 
>   default_scope { order(created_at: :desc) }
> 

There would be a difference in behaviour because default scopes are greedy and 
need explicit unscoping to override. This can result in unexpected/surprising 
behaviour. To illustrate this using the default scope described above, calling

Model.order(:name).first

Would result in the following order clause:

…ORDER BY created_at DESC, name ASC…

i.e. the default scope ordering is always included and any additional order 
clauses are appended. You’d have to remember to call reorder() or unscoped() 
instead.

A configurable default order column would differ in that it would be a fallback 
if no explicit order is specified, i.e. the order clause would look like:

…ORDER BY name ASC…


Tekin

-- 
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 rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to