-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:
<pre><code>
class Dict
include Mongoid::Document
embeds_many :keys
end
class Key
include Mongoid::Document
include Mongoid::Timestamps
field :name
key :name
validates_uniqueness_of :name
embedded_in :dict, :inverse_of => :keys
end
</code></pre>
no issue if I comment "key :name" in Key class. But if I enable it, the unique validator will fail.
In code UniquenessValidator line 39, the criteria fails to work because _id is the attribute. It will also return false when invoking exists? method later.
criteria = criteria.where(attribute => unique_search_value(value), :_id =>
)
Remove the second condition, the unique works fine.
criteria = criteria.where(attribute => unique_search_value(value))
another issue:
If I use key method on name, I thought the name should be unique by default? but it is not in fact. Not sure the reason.