adonis many to many 1

adonis many to many

@manyToMany(() => Skill, {
  localKey: 'id',
  pivotForeignKey: 'user_id',
  relatedKey: 'id',
  pivotRelatedForeignKey: 'skill_id',
})
public skills: ManyToMany

Here is what the above code is Doing:
1. We are defining a many-to-many relationship between the User and Skill models.
2. We are telling Lucid that the local key is the id of the User model.
3. We are telling Lucid that the foreign key on the pivot table is user_id.
4. We are telling Lucid that the related key is the id of the Skill model.
5. We are telling Lucid that the related foreign key on the pivot table is skill_id.

Now, let’s see how we can use this relationship.

Similar Posts