Reputation: 3869
I have this classes:
class Fruit
attr_accessible :name, :position
has_many :apples
default_scope order('position ASC')
end
class Apple
attr_accessible :name
belongs_to :fruit
end
How sort apples by fruit.position?
Upvotes: 11
Views: 11167
Reputation: 5398
You can do it like this:
@apples.joins(:fruit).order(Fruit.arel_table[:position])
Upvotes: 3
Reputation: 3869
Sorry guys, I think it must be like this: @apples.joins(:fruit).order("fruits.position")
Upvotes: 23