I have the following scope in a Rails model.
class Suggestion < ActiveRecord::Base
has_many :favourites
def self.favoured_by(user)
joins(:favourites).where(favourites: { user_id: user.id })
end
end
That works perfectly. It will return all the suggestions which a particular user has favourited.
How can I retrieve all the suggestions which are either not favourited at all or which are favourited but not by this particular user?
def self.not_favoured_by(user)
# ...
end
My Favourite model looks like this:
class Favourite < ActiveRecord::Base
belongs_to :suggestion
belongs_to :user
end
1 Answer