Ruby on Rails sorting and parenting children relationship

1

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.

    
asked by anonymous 01.09.2016 / 13:52

1 answer

1

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.

    
01.09.2016 / 20:25