On Thursday, 15 May 2014 09:56:11 UTC-4, Henrique Vilela wrote:
>
> Hi Colin, thank you for your answer.
> I just realized that my problem is bigger than that. I removed the
> default_scope and my query now is "orderbyless".
>
> SELECT "patterns".* FROM "patterns" INNER JOIN "patterns_patterns" ON
> "patterns"."id" = "patterns_patterns"."child_id" WHERE
> "patterns_patterns"."parent_id" = ? [["parent_id", 7]]
>
> Why the order is been ignored?
>
> class Pattern < ActiveRecord::Base
>
> has_and_belongs_to_many :children,
>
> :class_name => 'Pattern',
>
> :join_table => 'patterns_patterns',
>
> :association_foreign_key => 'child_id',
>
> :foreign_key => 'parent_id',
>
> :order => 'patterns_patterns.updated_at'
>
> end
>
>
The `order` option was removed a while back - things that change the query
should be done in a scope lambda instead:
has_and_belongs_to_many :children, -> { order(:something) }, ...
--Matt Jones
> Quinta-feira, 15 de Maio de 2014 5:34:26 UTC-3, Colin Law escreveu:
>>
>> On 14 May 2014 19:13, Henrique Vilela <[email protected]> wrote:
>> > I'm trying to set a specific order to an association, but I keep
>> getting the
>> > default scope order definition.
>> >
>> > What am I missing?
>>
>> I tend to avoid default_scope for exactly this reason, the results are
>> not always obvious. I prefer to use named scopes or specify the order
>> explicitly. Then you have better control of what is going on. Many
>> believe default scopes are evil. I believe you can override it using
>> reorder.
>>
>> Colin
>>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/06ab2c15-f328-494c-b620-55951065f94e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.