title: Unique Association :through
body: <p>I have a many to many :through relationship between a set of classes like so:</p>
  
  <pre><code>class Company
    has_many :shares
    has_many :users, :through =&gt; :shares, :uniq =&gt; true
  end
  
  class User
    has_many :shares
    has_many :companys, :through =&gt; :shares, uniq =&gt; true
  end
  
  class Share
    belongs_to :company
    belongs_to :user
  end
  </code></pre>
  
  <p>I want to ensure a unique relationship so that a user can only have one share in any one company, which is what I have tried to achieve using the "uniq" argument.</p>
  
  <p>At first I thought this was working, however it seems the behaviour os the "uniq" is to filter on the SELECT of the record, not pre-INSERT so I still get duplicate records in the database, which becomes an issue if I want to start dealing with the :shares association directly, as calling user.shares will return duplicate records if they exist.</p>
  
  <p>Can anyone help with an approach which would force truely uniq relationships? so that if I try adding the second relationships between a user and a company it will reject it and only keep the original?</p>