On Wednesday, 14 May 2014 14:13:51 UTC-4, Henrique Vilela 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?
>
>
> class Pattern < ActiveRecord::Base
>
> default_scope { order('sort, title') }
>
> 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
>
>
> SELECT "patterns".* FROM "patterns" INNER JOIN "patterns_patterns" ON
> "patterns"."id" = "patterns_patterns"."child_id" WHERE
> "patterns_patterns"."parent_id" = ? ORDER BY sort, title [["parent_id",
> 1]]
>
Which Rails version are you running? There were a substantial number of
issues with default_scope fixed in 4.0 and 4.1.
--Matt Jones
--
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/3c437414-b1c1-4834-a459-c66a58e5803c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.