Forked from jakobdamjensen/find_documents_based_on_region.js
Last active
August 29, 2015 14:07
-
-
Save beppu/8b6275b184b0e14f9c5e 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
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