Loopback: Bug: nestRemoting bad applied over a referencesMany Model

Created on 26 Jan 2018  路  11Comments  路  Source: strongloop/loopback

Description/Steps to reproduce

Supose that model A is a model which contains a relation referencesMany with model B. Then if a model C extends the model A functionalities (endpoints) using nestRemoting, we have a problem.

The error is "Error: Invalid remote method: __exists__relatedModelBName"

Thanks.

bug help wanted stale

Most helpful comment

Try doing this. At least, this was my patch.

 // Added because referencesMany bug
  ModelA.prototype.__exists__modelBs = function(fk, options, cb) {
    let self = this
    let types = self['modelBIds']
    if (types.indexOf(fk) > -1) cb()
    else {
      let error = new Error()
      error.statusCode = 404
      cb(error)
    }
    return cb.promise
  }

And done. The inheritance is solved. But wait... that's another bug haha, but for now it solves that problem.

The new bug is found in this thread -> https://github.com/strongloop/loopback/issues/4002

Good luck!

All 11 comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I am running into the same problem here. My setup is similar to @sebastianfelipe 's, after I had to change a relation type from "embedsMany" to "referencesMany":

PersistedModelA embedsOne ModelB
ModelB referencesMany PersistedModelC
PersistedModelA.nestRemoting("ModelB")

Also getting the error
"Cannot load the LoopBack application: Invalid remote method: __exists__PersistedModelC"

Removing nestRemoting for PersistedModelA removes the error - but also the sweet advantages of nested queries.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

That bug is still not solved. Any updates?

Any Update on this issue?

I submitted a PR here https://github.com/strongloop/loopback-datasource-juggler/pull/1614
But had some bugs compiling and didn't have much time to look at it again :/

Try doing this. At least, this was my patch.

 // Added because referencesMany bug
  ModelA.prototype.__exists__modelBs = function(fk, options, cb) {
    let self = this
    let types = self['modelBIds']
    if (types.indexOf(fk) > -1) cb()
    else {
      let error = new Error()
      error.statusCode = 404
      cb(error)
    }
    return cb.promise
  }

And done. The inheritance is solved. But wait... that's another bug haha, but for now it solves that problem.

The new bug is found in this thread -> https://github.com/strongloop/loopback/issues/4002

Good luck!

Sorry for the silence on our side. I am afraid we don't have bandwidth to investigate and fix this bug, but I am happy to help you along the way if you decide to contribute the fix yourself.

Here are is our contributing guide to get you started: https://loopback.io/doc/en/contrib/code-contrib.html

Just remember to include one or more tests that demonstrate the problem, fail with the current version and pass with your fix in place.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ritch picture ritch  路  40Comments

stringbeans picture stringbeans  路  40Comments

ritch picture ritch  路  55Comments

daankets picture daankets  路  244Comments

bajtos picture bajtos  路  66Comments