Skip to content

Commit 81c0cf7

Browse files
committed
Fix _embed
1 parent 1b0ab8c commit 81c0cf7

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/router.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ module.exports = function (source) {
145145
// GET /:resource/:id
146146
function show (req, res, next) {
147147
var _embed = req.query._embed
148+
var id = utils.toNative(req.params.id)
148149
var resource = db(req.params.resource)
149-
.get(utils.toNative(req.params.id))
150+
.get(id)
150151

151152
if (resource) {
152153
// Clone resource to avoid making changes to the underlying object
@@ -156,12 +157,15 @@ module.exports = function (source) {
156157

157158
// Embed other resources based on resource id
158159
_embed.forEach(function (otherResource) {
159-
if (otherResource && otherResource.trim().length > 0) {
160-
// Skip non-existent collections
161-
if (!db.object[otherResource]) return
160+
161+
if (otherResource
162+
&& otherResource.trim().length > 0
163+
&& db.object[otherResource]) {
162164
var query = {}
163-
query[req.params.resource + 'Id'] = req.params.id
165+
var prop = pluralize.singular(req.params.resource) + 'Id'
166+
query[prop] = id
164167
resource[otherResource] = db(otherResource).where(query)
168+
165169
}
166170
})
167171

0 commit comments

Comments
 (0)