If I remove the unique=true from the constraint it also works.
This is not an answer to your question, but I will ask why would you add the unique as a constraint that way? Not fully knowing how the validation part of ColdBox works, I would be more inclined to add that attribute to the actual property and let CF-ORM actually take care of the validation rules for unique.
When designing Databases, a rule of thumb is that the Database should adhere to validations as well.
The documentation states
Unique | Boolean | The value must be unique in the ORM object table
So I was assuming that this would provide a friendly way to check if the given value was unique before saving it. If the validation rule sees the error then that would leave all of my error messaging for a failure in one place.
I will definitely add the unique value to the ORM property to help ensure that it is unique in case the validation get’s forgotten at some point in time.
I agree that the database should adhere to the validation as well, my database already has a unique index on the username column.
Is that the validation documentation?
Cool, wasn’t trying to tell you what to do. It was more of a reference that one should, as the code you did provide didn’t have that added.
Yeah I think unique is probably a different validation problem, and the reason is that you need to hit the database and search for the existence anyway. As there is no other way the data could be seen as unique or not, so my logic would be to let the CF-ORM take control for you when it saves the object. I guess the latter part is more on how you want to handle large amounts of queries here, or keep the database access to a minimum as much as possible.
Yes, the reference was to the ColdBox documentation (http://wiki.coldbox.org/wiki/Validation.cfm#Validating_Constraints).