Skip to content

Instantly share code, notes, and snippets.

@ebramanti
Created August 23, 2016 23:24
Show Gist options
  • Save ebramanti/fce1844b5b1d94f5884cdee00103be7e to your computer and use it in GitHub Desktop.
Save ebramanti/fce1844b5b1d94f5884cdee00103be7e to your computer and use it in GitHub Desktop.
var Promise = require('bluebird');
Bookshelf.transaction(Promise.coroutine(function*(t) {
const library = yield Library.forge({name: 'Old Books'}).save(null, {transacting: t});
return yield Promise.map(
[
{ title: 'Canterbury Tales' },
{ title: 'Moby Dick' },
{ title: 'Hamlet' }
],
(info) => Book.forge(info).save({ 'shelf_id': library.get("id") }, {transacting: t})
);
}))
.then((library) => console.log(library.related('books').pluck('title')))
.catch((err) => console.error(err));
@juliancoleman
Copy link

return yield OP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment