Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample sequelize
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