diff options
| author | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-08 15:04:48 -0400 |
|---|---|---|
| committer | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-08 15:05:41 -0400 |
| commit | 2a4ede6507f55e492736c4b82a139ac5d2e2eec0 (patch) | |
| tree | 4193f453936c21e64815f3ecba82726c0ac4c4ef | |
| parent | 88d83bc72eb7162dc8877de1aaf5269ee10e41bc (diff) | |
Update OKAdminView template data fetch for custom IDs
| -rw-r--r-- | app/node_modules/okutil/index.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/app/node_modules/okutil/index.js b/app/node_modules/okutil/index.js index 738c6a4..01041b6 100644 --- a/app/node_modules/okutil/index.js +++ b/app/node_modules/okutil/index.js @@ -24,17 +24,27 @@ module.exports = { }))) .then(function(results) { var metadata = results.shift(); - var normalized = results.reduce(function(data, result, i) { + var normalized = results.reduce(function(cache, result, i) { + var resource = queries[i].resource; var type = queries[i].type; + var plural = pluralize(type); if (isarray(result)) { - data[pluralize(type)] = result; + result = result.map(function(data) { + // Inform template of ID in generic way + data.id = data[resource.idField]; + return data; + }); } else { - data[type] = result; + // Inform template of ID in generic way + result.id = result[resource.idField]; + result = [result] } - return data; + cache[plural] = cache[plural] || []; + cache[plural] = cache[plural].concat(result); + return cache; }, {meta: metadata}); resolve(normalized); - }, reject); + }).fail(reject); }); }, |
