Skip to content

nestRemoting() throws TypeError without {hooks:false} hack #1951

Description

@timneedham

Hi,

Really loving Loopback and the community... but just can't crack this. Spent a few days in the docs and can't find anything obviously wrong...

If I call nestRemoting() on a model with the option hooks:false set, then things are fine.
Having to provide options isn't mentioned in the docs... so I guess this is masking a deeper problem?

If planet is the top-level model, which hasMany moon[s], which in-turn hasMany crater[s]...

And we've planet.nestRemoting('moons'), then posting to /api/planets, with the hooks:false option omitted, results in:

TypeError: Cannot read property 'moon' of undefined
    at EventEmitter.<anonymous> (/home/tim/GithubProjects/nest-remoting-issue/node_modules/loopback/lib/model.js:809:58)
    at EventEmitter.g (events.js:260:16)
    at emitThree (events.js:97:13)
    at EventEmitter.emit (events.js:175:7)
    at /home/tim/GithubProjects/nest-remoting-issue/node_modules/loopback/lib/application.js:279:22
    at Array.forEach (native)
    at EventEmitter.app.handler (/home/tim/GithubProjects/nest-remoting-issue/node_modules/loopback/lib/application.js:278:21)
    at /home/tim/GithubProjects/nest-remoting-issue/node_modules/loopback/server/middleware/rest.js:65:20
    at /home/tim/GithubProjects/nest-remoting-issue/node_modules/loopback/server/middleware/rest.js:72:7
    at iterate (/home/tim/GithubProjects/nest-remoting-issue/node_modules/async/lib/async.js:146:13)

Which seems to point to something not being quite right with the way our remotes are set-up? This is the line in Model.nestRemoting that fails:

var beforeListeners = remotes.listenerTree.before[toModelName] || {};

  • ...because remotes.listenerTree is an empty object with no before key.
  • I've made a repo to replicate this issue here.
  • And this might be a clue: once that first post fails, any subsequent posts to the same endpoint work just fine!

I guess I'm doing something stupid/in the wrong order/wrong timing when booting, but just can't find it.

We would really appreciate some assistance as this is (hopefully) the last snag before we commit to Loopback in our next project.

Thanks in advance, keep up the great work!

Tim

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions