node-orm2
node-orm2 copied to clipboard
Unique Constraint for Multiple Columns?
I am wondering if this is possible to have a unique constraint across multiple columns. If not with the ORM, what would the best way to add this either to the ORM or manually?
http://stackoverflow.com/questions/635937/how-do-i-specify-unique-constraint-for-multiple-columns-in-mysql
Thanks, Joe
Like this?
const User = db.define('user', {
username : { type: 'text' },
firstname: { type: 'text', unique: 'fullname' },
lastname : { type: 'text', unique: 'fullname' },
});
The standard that I'd go for though is field1_field2
and maybe also abbreviate it if you can. So firstname_lastname
for the unique key.