Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What appears to be happening in this case and the cause of your error is that <code>Model.User</code> is actually not an instance of <code>UserProvider</code> but appears to point to a function called <code>Model</code> defined as...</p> <pre><code>function Model(doc, fields, skipId) { if(!(this instanceof Model)) return new Model(doc, fields, skipId); model.call(this, doc, fields, skipId); } </code></pre> <p>Now this assignment could be happen at three places within your code...</p> <pre><code>var Model = new ModelProvider(); // Here sets Model.User Model.User.findUserByEmail(...); </code></pre> <p>Or...</p> <pre><code>function ModelProvider() { ... this.User = new UserProvider(db); // Here sets this.User } </code></pre> <p>Or...</p> <pre><code>function UserProvider(db) { // Here as a return statement } </code></pre> <p>I would guess the latter is probably where the issue is happening.</p> <hr> <p>To be clear all of the following are possible in NodeJS...</p> <p><strong>Importing a constructor from a module that didn't necessarily contain it...</strong> To be clear you <em>shouldn't</em> do this but it is possible to chain the exports so that a module exposes items from other modules it imports. You <em>should</em> import modules explicitly.</p> <p>module.js...</p> <pre><code>var Something = require("./something").Something; exports.Something; </code></pre> <p>main.js...</p> <pre><code>var Something = require("./module").Something; </code></pre> <p><strong>Repeat</strong> do <em>not</em> do this. Instead include what you need from the module that <em>owns</em> it and don't export anything the module doesn't own. I've only included this example to clarify what exports and require can do.</p> <hr> <p><strong>Access an instance created in another module...</strong> You can export the instance via the exports object as you would a constructor.</p> <p>module.js...</p> <pre><code>function MySomething() { //... } exports.mySomething = new MySomething(); </code></pre> <p>main.js...</p> <pre><code>var mySomething = require("./module").mySomething; </code></pre> <hr> <p><strong>Through an instance of an imported constructor, access an instance of a constructor that it has also imported...</strong> You can expose it through the <code>this</code> scope in which case it will be accessible through the public members of the instance you create of the constructor you imported.</p> <p>module.js...</p> <pre><code>var Something = require("./something").Something; function MySomething() { this.something = new Something(); } exports.MySomething = MySomething; </code></pre> <p>main.js...</p> <pre><code>var MySomething = require("./module").MySomething; var mySomething = new MySomething(); mySomething.something; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload