Created
August 23, 2016 23:24
-
-
Save ebramanti/fce1844b5b1d94f5884cdee00103be7e to your computer and use it in GitHub Desktop.
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
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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return yield
OP