Bookshelfjs NPM
const knex = require('knex')({ client: 'mysql', connection: process.env.MYSQL_DATABASE_CONNECTION})const bookshelf = require('bookshelf')(knex) const User = bookshelf.model('User', { tableName: 'users', posts() { return this.hasMany(Posts) }}) const Post = bookshelf.model('Post', { tableName: 'posts', tags() { return this.belongsToMany(Tag) }}) const Tag = bookshelf.model('Tag', { tableName: 'tags'}) new User({id: 1}).fetch({withRelated: ['posts.tags']}).then((user) => { console.log(user.related('posts').toJSON())}).catch((error) => { console.error(error)})
Healthy Horse