var Customer = Bookshelf.Model.extend({
tableName : 'customers',
accounts : function() {
return this.hasMany(Account, 'customerId');
}
});
var Account = Bookshelf.Model.extend({
tableName : 'accounts',
customer : function() {
return this.belongsTo(Customer, 'customerId');
},
});
I'm trying to get all accounts where accounts.name = 'Smith' and customers.pro = true.
knex solution:
knex('accounts')
.join('customers', 'customers.id', 'accounts.customerId')
.where('customers.pro', '=', true)
.where('accounts.name', '=', 'Smith')
.select()
.then (accounts) ->
// success code