activerecord - Using method in a where clause Rails Ruby Active Record -
i wondering if posible use model instance method clause query. mean. have model school method defined class school < activerecord::base def my_method users.where(blablabla).present? end end is posible like: school.all.where(my_method: true) i know can like: school.all.map{|x| x if x.my_method} but way has huge penalization in performance compared query. furthermore, return of i'm searching activerecord relation , map returns array. update: also there way like: school.all.joins(:users).where("users.attribute = something") but not fit want several reasons. thanks in advance i don't know relations between models. but clause gets hash of key - value. can example return id's of users in kind of hash , use it. def my_method {user_id: users.where(blablabla).ids} end and use it: school.all.where(my_method)