Created
August 30, 2013 19:12
-
-
Save brianjmiller/6393294 to your computer and use it in GitHub Desktop.
Sample sequelize
This file contains hidden or 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
Uri.findAll( | |
{ | |
include: [ | |
{ model: CurrentMetaData, as: "metadata" } | |
], | |
where: { | |
type: revTypeMap[type] | |
} | |
} | |
).then( | |
function (models) { | |
var chainer = new Sequelize.Utils.QueryChainer(); | |
models.forEach( | |
function (model) { | |
var emitter = new Sequelize.Utils.CustomEventEmitter( | |
function () { | |
model.metadatum.getMetadata().then( | |
function (metadata) { | |
var subresult = model.toJSON(); | |
subresult.metadata = metadata.toJSON(); | |
subresult.metadata.metadata = JSON.parse(subresult.metadata.metadata); | |
delete subresult.metadatum; | |
result.push(subresult); | |
emitter.emit("success"); | |
} | |
); | |
} | |
); | |
chainer.add(emitter.run()); | |
} | |
); | |
chainer.run().on( | |
"success", | |
function () { | |
self.res.json(result); | |
} | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment