title: Ruby on Rails self.joins or self.where doesn't work?
body: <p>my actual code looks like this</p>
  
  <pre><code>user_lesson = self.where("worked = ? AND passed = ?", true, false).order("lessons.sort")
  </code></pre>
  
  <p>But it doesn't work ... error is: </p>
  
  <pre><code>undefined method `where' for #&lt;Membership:0x000000059f22e8&gt;
  </code></pre>
  
  <p>.. I've tried it this way:</p>
  
  <pre><code>user_lesson = Membership.joins("user_lessons").where("id = ? AND worked = ? AND passed = ?",self.id, true, false).order("lessons.sort")
  </code></pre>
  
  <p>But then I got this error:</p>
  
  <pre><code>Unknown table 'memberships': SELECT `memberships`.*
  FROM `memberships` user_lessons
  WHERE (id = 4 AND worked = 1 AND passed = 0)
  ORDER BY lessons.sort
  </code></pre>
  
  <p>How should it look like correctly?</p>
  
  <p>Original Query</p>
  
  <pre><code>user_lesson = self.user_lessons.find :first,
    :include =&gt; [:lesson],
    :conditions =&gt; ["worked = ? AND passed = ?", true, false],
    :order =&gt; "lessons.sort"
  </code></pre>