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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -