
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 Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
- Nobody is watching this ticket.