Reputation: 1089
I have a Model (Activity) with a has_one
relation to another Model (OverallRating) which has a column called overall
I want to sort the Activities
based on the overall
column. I have searched about this but was unlucky and found very specific stuff that aren't really as simple as my question here.
Upvotes: 0
Views: 214
Reputation: 1089
Thanks a lot to BroiSatse he gave me a headstart. However this is what worked for me.
Activity.joins(:overall_rating).select("activities.*").order('overall')
Upvotes: 0
Reputation: 44675
That will do for has_one:
Activities.joins(:overall_rating).order('overall_ratings.overall').uniq
I am pretty sure this will also work for has_many association (just add an s to the symbol in joins
method) however has not tested it yet.
Upvotes: 1