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?
Sorry guys, I think it must be like this: @apples.joins(:fruit).order("fruits.position")
You can do it like this:
@apples.joins(:fruit).order(Fruit.arel_table[:position])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With