Vincit / objection.js

An SQL-friendly ORM for Node.js
https://vincit.github.io/objection.js
MIT License
7.27k stars 639 forks source link

HasMany through relation Feature Request #2293

Closed kaushal-aubie closed 1 year ago

kaushal-aubie commented 2 years ago

Does objection has HasManyRelation through relation, I wanted something like this

users: {
        relation: Model.HasManyRelation,   // hasManyThorugh needed
        modelClass: User,
        join: {
          from: 'marksheets.id',
          through: {
            modelClass: MarksheetMember,
            from: 'marksheetMembers.marksheetid',
            to: 'marksheetMembers.userId',
          },
          to: 'users.id',
        },
      },

Otherwise, i have to

await db.Marksheet.query().findById(marksheetId).withGraphFetched('users.user') // if it is not through relation
abedmurrar commented 2 years ago

HasManyThrough is a ManyToMany Relation, you could just use ManyToMany