dresende / node-orm2

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

How to set multiple unique index with auto generated column from `.hasOne()` method. #808

Closed reumia closed 6 years ago

reumia commented 6 years ago

I made associations like this.

const LikesComic = db.models['likes_comic']

LikesComic.hasOne('target', Comics)
LikesComic.hasOne('user', Users)

then, target_id and user_id columns are created automatically on likes_comic table.

and I want to set multiple unique index like this.

// if these columns - user_id & target_id - are not created automatically,
db.define('likes_comic', {
  user_id: {type: 'integer', unique: 'user_id_target_id'},
  target_id: {type: 'integer', unique: 'user_id_target_id'}
})

my currently defining is like above.

db.define('likes_comic', {
  // nothings on here.
})

is there any way to do this?

reumia commented 6 years ago

moved to #816