Rails, how to create a scope where a habtm is populated? -
i have user accounts has habtm relationship companies. users can have 0 companies. write scope users belong 1 or more companies. how can accomplish this?
example model:
class user < activerecord::base has_and_belongs_to_many :companies scope :independent, # ???? end
for no companies:
scope :independent, -> { where(:companies => []) }
for 1 or more companies:
scope :independent, -> { where("companies <> []") }
Comments
Post a Comment