Solution for where clause in Many Through

If anybody has problems querying data with manyThrough relations, keep in mind that you have to specify the model inside the .where(‘model.bar’)

example taken from docs:

const Model = use('Model')

class User extends Model {
  posts () {
    return this.hasMany('App/Models/Post')
  }
}
const Model = use('Model')

class Country extends Model {
  posts () {
    return this.manyThrough('App/Models/User', 'posts')
  }
}
        const posts= await country
            .posts()
            .where('post.uuid', uuid)
            .first()

Hope that google will index this in case you need it in the future.

Cheers!

1 Like