Skip to content

Instantly share code, notes, and snippets.

@jwhitmarsh
Created July 9, 2015 14:05
Show Gist options
  • Save jwhitmarsh/d24ae49a92964192d6a9 to your computer and use it in GitHub Desktop.
Save jwhitmarsh/d24ae49a92964192d6a9 to your computer and use it in GitHub Desktop.
Sequelize left join from two tables
Extraction.findAll({
where: {
archived: false
},
attributes: ['id', 'createdAt', 'updatedAt'],
include: [
{
model: ExtractionTemplate,
attributes: ['id'],
where: {
extractionTemplateTypeId: id
},
include: [
{
model: FieldCategory,
attributes: ['id'],
where: {
parentId: null
},
required: false,
include: [
{
model: Field,
attributes: ['id', 'label', 'isBaseline'],
where: {
isBaseline: true
},
required: false,
include: [
{
model: FieldValue,
attributes: ['id', 'value', 'extractionId'],
where: {
extractionId: 0 // I NEED TO GET THE EXTRACTION ID HERE
},
required: false
}
]
}
]
}
]
}
],
raw: raw
}).then(function(extractions) {
cb(0, extractions);
}).catch(function(err) {
app.log.error('Extractions getAll error:' + err.message);
cb(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment