node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

Unique Constraint for Multiple Columns?

Open jsammarco opened this issue 8 years ago • 1 comments

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

jsammarco avatar Mar 07 '16 16:03 jsammarco

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.

nallown avatar Mar 14 '16 03:03 nallown