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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -