Created
April 20, 2015 04:44
-
-
Save VictorQueiroz/9c5ed701309654a7897c to your computer and use it in GitHub Desktop.
bookshelf.js - Updating related models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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