mbouclas / loopback-ds-tree-mixin

Transform a loopback model into a tree using the Array of Ancestors pattern
MIT License
6 stars 4 forks source link

Invalid remote method `__exists__ancestorObjects` on application startup #23

Open bjardon opened 5 years ago

bjardon commented 5 years ago

I installed and configured the mixin following the documentation, but when launching the app an exception prevents the app from running.

Error: Invalid remote method `__exists__ancestorObjects`
at /Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/loopback/lib/model.js:944:19
    at Array.forEach (<anonymous>)
    at Function.Model.nestRemoting (/Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/loopback/lib/model.js:931:31)
    at resolver (/Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/loopback/lib/model.js:293:21)
    at /Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/strong-remoting/lib/shared-class.js:114:14
    at Array.forEach (<anonymous>)
    at SharedClass.methods (/Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/strong-remoting/lib/shared-class.js:113:19)
    at Function.Model.nestRemoting (/Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/loopback/lib/model.js:931:21)
    at resolver (/Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/loopback/lib/model.js:293:21)
    at /Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/strong-remoting/lib/shared-class.js:114:14
    at Array.forEach (<anonymous>)
    at SharedClass.methods (/Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/strong-remoting/lib/shared-class.js:113:19)
    at Function.Model.nestRemoting (/Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/loopback/lib/model.js:931:21)
    at resolver (/Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/loopback/lib/model.js:293:21)
    at /Users/brunojardon/Documents/Burk/Wei/source/master/api/node_modules/strong-remoting/lib/shared-class.js:114:14
    at Array.forEach (<anonymous>)

I double checked the config and made sure I followed each step in the docs, but can't figure out the error.

The application launches successfully if I remove the mixins object from the model json file, however the tree methods are not initialized.

bjardon commented 5 years ago

So; I've been working on this for quite some time and made some progress, but haven't been able to fix the error altogether. This is what I've learned.

The cause of the exception is the remote method itself. When the loopback's model.js script attempts to register the method, it checks the typeof the nestedFn; if it is anything other than function the above mentioned exception is thrown.

After some debugging and a lot of console.logs I found that the model's prototype does not contain a function called __exists__ancestorObjects; thus encounters an undefined value.