Skip to content

Instantly share code, notes, and snippets.

@VictorQueiroz
Created April 20, 2015 04:44
Show Gist options
  • Save VictorQueiroz/9c5ed701309654a7897c to your computer and use it in GitHub Desktop.
Save VictorQueiroz/9c5ed701309654a7897c to your computer and use it in GitHub Desktop.
bookshelf.js - Updating related models
Account.query(function (q) {
q.where('account.id', '=', 1);
q.distinct().innerJoin('account_accounts', function () {
this.on('account.id', '=', 'account_accounts.id');
});
}).fetch({
withRelated: ['accounts']
}).then(function (account) {
return account.related('accounts').query(function (qb) {
qb.where('account.id', '=', 1006);
}).fetch();
}).then(function (accounts) {
return Account.forge({
id: accounts.at(0).get('id')
}).save({
username: 'minhaconta59',
sha_pass_hash: '123456'
}, {
patch: true
});
}).then(function (account) {
console.log(account.get('username'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment