I have a simple Model - Shop in my Ruby/MongoMapper application.
I have no idea why sometimes I only get one error message, and sometimes I get three error messages like this one:
'Validation failed: User has already been taken, User has already been taken, User has already been taken'
Yes, I am adding the same user_id multiple times, on purpose.
Here is my code:
class Shop
include MongoMapper::Document
key :user_id, String, :required => true, :unique => true
def self.add
begin
ut = Shop.new
ut.user_id = '11'
ut.save!
ut = nil
rescue Exception => e
puts e.message
end
end
end
Result:
# 'Validation failed: User has already been taken, User has already been taken, User has already been taken'
UPDATE:
Seems like removing the
ut = nil
fixes the 'problem'. But why...