I have a parent table and a child table, I would like to know how do I make a query in the child table but sort by a column of the parent table. I want to know all the children and sort them out by the age of the father.
I have a parent table and a child table, I would like to know how do I make a query in the child table but sort by a column of the parent table. I want to know all the children and sort them out by the age of the father.
Considering that there is a has_many/belongs_to
relationship between the Pai
model and the Filho
template, you can do the following:
Filho.includes('pai').order('pais.idade DESC')
Ready, it will return all the children by the age of the parent.