irlnathan / activityoverlord

An application I'm building to learn sails.js
317 stars 101 forks source link

Unique: true validation rule #9

Closed johnnncodes closed 10 years ago

johnnncodes commented 10 years ago

Hey there,

Thanks for the tutorials. I learned a lot about sails.js because of you.

Anyway, I'm confused with the unique: true model attribute for validation. It returns a different format than other validators like maxLength etc.. this is the error being returned by unique:true - MongoError: E11000 duplicate key error index: sails_twitter.user.$username_1 dup key: { : "ken" } while maxLength etc.. returns - { ValidationError: { password: [ [Object], [Object] ] } } . Because of that I can easily render the error messages for maxLength, minLength etc.. but having a hard time on how to display the error message for unique: true; rule because the error message is a different format.

Also, I can't see the unique rule in anchor.js w/c is used by waterline.js for validation - https://github.com/balderdashy/anchor/blob/master/lib/rules.js

is unique rule really supported? 

flipflopsimsommer commented 10 years ago

Where did you find the unique attribute? it's not mention in the doku any more (i use it too and have problems thanks to your question i had a good idea, but i need the part again where the mentiont unique adapter attr.) looks like the removed it again?

johnnncodes commented 10 years ago

If I'm not mistaken, the app level (validator - Anchor) doesn't really validate that the model attribute like username is unique, if unique: true is set, it validates in the database level like if you're using MongoDB it just creates a unique index to ensure that it will be unique, I think that's why it throws a different error message format.