title: Rails validating uniqueness of polymorphic association
body: <p>I have the following:</p>
  
  <pre><code>class Membership &lt; ApplicationRecord
    belongs_to :member, polymorphic: true
    belongs_to :group, polymorphic: true
  end
  </code></pre>
  
  <p>As you can see my Membership model is doubly polymorphic. I want to validate the uniqueness of <code>:member</code> scoped by <code>:group</code>. </p>
  
  <p>I was hoping the following would work:</p>
  
  <pre><code>validates :member, uniqueness: { scope: :group }
  </code></pre>
  
  <p>But this causes an error:</p>
  
  <pre><code>NameError: uninitialized constant Membership::Member
  </code></pre>
  
  <p>Is there a Rails way of doing this, or do I need to write a custom method for it?</p>