String property type primary key and validates_is_unique won't work
Reported by Aaron Qian | July 3rd, 2008 @ 11:16 AM
Problem:
When I used a string property type as the primary key, validates_is_unique always passes (returns true).
How to reproduce:
class User
include DataMapper::Resource
property :login, String, :key => true
property :email, String, :nullable => false, :format => :email_address
...
...
validates_is_unique :login
end
under interactive console...
u1 = User.new(:login => "user1", email => "me@domaint.tld")
u1.save ---> true
u2 = User.new(:login => "user1", email => "a@different.one")
u2.valid? ----> true
u1 == u2 -------> true
u2.save -------> exception, duplicate primary_key...
Possible Solution
change the "==" to be more robust so it can identify if the resources are new records or not, and compare fields?
recognize "key" symbol in auto validation?
Comments and changes to this ticket
-
Bernerd Schaefer July 30th, 2008 @ 10:56 AM
- → State changed from new to resolved
- → Tag changed from validations to bug dm-more validations
As of 76b8e53, this should be fixed. The validation code was assuming that the key would be different than the unique field.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
