mongoid/mongoid — Issue #1391: validates_uniqueness_of embedded_document with key
Author: danielnc
Created: 2011-10-31 20:42:55+00:00
State: open

```ruby
class Seller
include Mongoid::Document
field :seller_id, :type => Integer
field :name, :type => String
embeds_many :seller_products
key :seller_id
end

class SellerProduct
include Mongoid::Document
field :product_id, :type => Integer
key :product_id
embedded_in :seller, :inverse_of => :seller_products
validates_uniqueness_of :product_id
end
````

Validates_uniqueness_of doesnt work if i set my key to be :product_id

Uniqueness validator criteria becomes:
10, :_id=>{"$ne"=>"10"}},
options: {},
class: SellerProduct,
embedded: true>

When i remove the key it works
#1, :_id=>{"$ne"=>BSON::ObjectId('4eaf0733a5d09fb9ef000006')}},
options: {},
class: SellerProduct,
embedded: true>