Association is like
class User < ActiveRecord::Base
has_many :products
has_many :ratings
I want to sort products according to user ratings. Let suppose I want to sort all those product whose ratings is greater than 4. I cant find any way to do that.
I do something like
User.joins(:ratings).where("ratings.rate > ?", 4).includes(:ratings)
From that I get all user whose ratings is greater than 4 but how join with product and sort them?
Aucun commentaire:
Enregistrer un commentaire