Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beppu/8b6275b184b0e14f9c5e to your computer and use it in GitHub Desktop.
Save beppu/8b6275b184b0e14f9c5e to your computer and use it in GitHub Desktop.
new Region()
.publishedDocuments()
.query(function(q){
q.join('regions', 'regions.id', '=', 'documentRegions.region_id');
q.whereIn('regions.id', regionIds);
q.where('publishedDocuments.updated_at', '>=', new Date(timestamp));
})
.fetchAll({withRelated: [
'publishedDocuments.images',
'publishedDocuments.ecareSections',
'publishedDocuments.regions']
})
.then(function (collection) {
var map = {}, keys, i, maxLength, result = [];
collection.forEach(function (region) {
region.relations.publishedDocuments.forEach(function (document) {
if (map[document.id] === undefined) {
map[document.id] = document;
result.push(document);
}
});
});
res.json({
total_documents: result.length,
documents: result
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment