dresende / node-orm2

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

Way to define unique constraint for multiple columns on Associations? #816

Open reumia opened 6 years ago

reumia commented 6 years ago

I already know the way to defining when define models like this.

db.define('likes_user', {
  userId: {type: 'integer', unique: 'userId_targetId'},
  targetId: {type: 'integer', unique: 'userId_targetId'}
})

but i define those keys automatically when make associations. so i want to know is there any ways for defining unique keys when make associations :(

here is my codes for associations. need helps!

LikesUser.hasOne('target', Users, {reverse: 'likes', field: 'targetId', mapsTo: 'target_id', required: true})
LikesUser.hasOne('user', Users, {reverse: 'likeUsers', field: 'userId', mapsTo: 'user_id', required: true})