ruby on rails - Finding objects using Activerecord with multiple conditions including a range -
i'm building rails app , trying find records in db using activerecord. there multiple models, of one-to-many relationships 1 many-to-many relationship , need able query can use id's various one-to-many models , array many-to-many.
the models follows:
class user < activerecord::base belongs_to :city belongs_to :company belongs_to :certification has_many :user_certifications has_many :certifications, :through => :user_certifications end class certification < activerecord::base has_many :user_certifications has_many :users, :through => :user_certifications end class city < activerecord::base has_many :users end i can query like:
user.where(['city_id = 1 , company_id = 3']) or using join , individual certification
user.joins(:certifications).where(['city_id = 1 , company_id = 3 , certification_id = 5']) but since user can have multiple certifications, need able search city 1, company 3, , certifications 5 + 6. ideas?
you looking in clause:
user.joins(:certifications).where(['city_id = 1 , company_id = 3 , certification_id in (5,6)'])
Comments
Post a Comment