ruby on rails, nested attributes, take highest attribute
I have a model called degree.rb
that belongs_to :user
(inside user.rb
- has_many :degrees
Let's say a user has 6 degrees. In the degrees table, there is a column called degree_type
that holds an int
. 开发者_运维技巧What is the best way to pull all 6 degrees and determine the highest degree_type
number in existence for that user?
It doesn't matter which entry is highest or even if there are duplicates. I just need to know what highest entry for degree_type
for a specific user exists.
Any suggs? Thanks!
Use maximum:
user.degrees.maximum( :degree_type )
精彩评论