dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

Unique Constraint for Multiple Columns? #712

Open jsammarco opened 8 years ago

jsammarco commented 8 years ago

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

nallown commented 8 years ago

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.