1
I have a parent table and a child table, I would like to know how to make a query in the child table but sort by a parent table column. Like I want to know all the kids and order them by father’s age.
1
I have a parent table and a child table, I would like to know how to make a query in the child table but sort by a parent table column. Like I want to know all the kids and order them by father’s age.
1
Whereas there is a relationship has_many/belongs_to
between the model Pai
and the model Filho
, you can do the following:
Filho.includes('pai').order('pais.idade DESC')
All right, all children will return by ordering by father’s age.
Browser other questions tagged ruby-on-rails
You are not signed in. Login or sign up in order to post.
Thank you, it worked perfectly :D
– André Gava
@Andrégava uowww, good! : D needing we are there!
– Luiz Carvalho