manyThrough() on Many-to-Many


#1

Is there support for manyThrough() on many-to-many type relationships?

Would this require creating a model for the pivot group_user?

My models include:

App/Models/User.js

...
class User extends Model {
  ...
  group () {
    return this.belongsToMany('App/Models/Group')
  }

  units () {
    return this.manyThrough('App/Models/Group', 'units')
  }
}
...

App/Models/Group.js

...
class Group extends Model {
  ...
  user () {
    return this.belongsToMany('App/Models/User')
  }

  units () {
    return this.hasMany('App/Models/Unit')
  }
}
...

App/Models/Unit.js

...
class Unit extends Model {
  ...
  group () {
    return this.belongsTo('App/Models/Group')
  }
}
...

I’d like to be able to get a record set that contains all of the units that are associated with a user via the groups they are associated with, like:

const some_users_units = user.units().fetch()

I understand based on the errors I’m getting why this isn’t working as it stands. But I couldn’t find anything related in the docs.

Is my only option to use join in a custom query?