title: Using method in a where clause Rails Ruby Active Record
body: <p>I wondering if it is posible to use a model instance method as a where clause query. I mean. I have a model School with a method defined</p>
  
  <pre><code>class School &lt; ActiveRecord::Base
  
    def my_method
      users.where(blablabla).present?
    end
  
  end
  </code></pre>
  
  <p>Is it posible to get something like:</p>
  
  <pre><code>School.all.where(my_method: true)
  </code></pre>
  
  <p>I know that I can do something like:</p>
  
  <pre><code>School.all.map{|x| x if x.my_method}
  </code></pre>
  
  <p>But this way has a huge penalization in performance compared to where query. Furthermore, the return of what I'm searching is an ActiveRecord Relation and map returns an array.</p>
  
  <p>UPDATE:</p>
  
  <p>Also there is another way to do it like:</p>
  
  <pre><code>School.all.joins(:users).where("users.attribute = something")
  </code></pre>
  
  <p>But this do not fit exactly what I want for several reasons.</p>
  
  <p>Thanks in advance</p>