Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- //const Bookshelf = require('./bookshelf');
- const Knex = require( 'knex' )( require('./config').database );
- const Bookshelf = require('bookshelf')( Knex );
- var Driver = Bookshelf.Model.extend({
- tableName: 'drivers',
- cars: function() {
- return this.hasMany( Car );
- }
- });
- var Car = Bookshelf.Model.extend({
- tableName: 'cars',
- driver: function() {
- return this.belongsTo( Driver );
- }
- });
- new Driver()
- .where({
- id: 2
- })
- .fetch({
- withRelated: ['cars']
- })
- .then((driver) => {
- console.log('RELATED CAR:', JSON.stringify(driver));
- Knex.destroy(() => {
- console.log('DONE');
- });
- });
Add Comment
Please, Sign In to add comment