Simple model:
class hat embedded_in :owner field :color end class owner embedds_one :hat referenced_in :house field :name end class house references_one :owner field :number end
It just poses, we have a collection of houses that are associated with the owner, and the owner can have a colored hat.
I can just sort the house by their number:
House.all.order_by( [[ :number, :asc ]])
But I want to order a house, by the name of its owner, ideally I would like to write:
House.all.order_by( [[ :'owner.name', :asc ]])
But this does not work ...
And even further, I would like to be able to sort houses by the color of the owner's hat
House.all.order_by( [[ :'owner.hat.color', :asc ]])
Any idea how I can achieve this without rewriting everything if possible :)
thanks
Alex
source share