Find ActiveRecord object by maximum field value of a child object?

前端 未结 4 717
太阳男子
太阳男子 2021-02-05 02:31

How can I find the object associated with the results of an ActiveRecord Calculation rather than a value?

For example I have @parent which has many children. I would lik

4条回答
  •  春和景丽
    2021-02-05 03:03

    @parent.children.first(:conditions => {:value => @parent.children.maximum(:value)})
    

提交回复
热议问题