Skip to content

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

Description

@reumia

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})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions