showing results for - "bookshelfjs npm"
Melina
23 Nov 2016
1const 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({id1}).fetch({withRelated: ['posts.tags']}).then((user) => {  console.log(user.related('posts').toJSON())}).catch((error) => {  console.error(error)})