title: Uniqueness field using Scope of association
body: <p>I want to insure that an items name is unique within an organization. So I've used the "validates_uniqueness_of :name, scope: [:organization]" within Item. This unfortunetely didn't work. </p>
  
  <p>Error (edited):</p>
  
  <pre><code>&gt;   1) Item 
  &gt;      Failure/Error: @item_1 = create(:item, :item_category =&gt; @item_cat_1)
  &gt;      
  &gt;      NoMethodError:
  &gt;        undefined method `organization_id' for #&lt;Item:0x00000002565840&gt;
  </code></pre>
  
  <p>models:</p>
  
  <pre><code>class Item &lt; ActiveRecord::Base
    belongs_to :item_category
    has_one :organization, through: :item_category
    validates_uniqueness_of :name, scope: [:organization]
  end
  
  class ItemCategory &lt; ActiveRecord::Base
      has_many :items
      belongs_to :organization
  end
  
  class Organization &lt; ActiveRecord::Base
    has_many :item_categories
    has_many :items, :through =&gt; item_categories
  end
  </code></pre>
  
  <p>In theory, as I did above may I use the item's, item_category association (belongs_to :item_category) for the organization_id?</p>
  
  <p>If the above isn't possible. I guess I could have an organization_id in the item and the item_category. But then how could we validate that a item.organization_id be always equal to an item_category.organization_id (its association)</p>