title: Fatal error: Schema hasn't been registered for model "a". Use mongoose.model(name, schema)
body: <p>I am having the following error:</p>
  
  <blockquote>
    <p>Fatal error: Schema hasn't been registered for model "a". Use
    mongoose.model(name, schema)</p>
  </blockquote>
  
  <p>Here is my file structure:</p>
  
  <p>--------a.model.js--------</p>
  
  <pre><code>'use strict';
   var mongoose = require('mongoose'),
   Schema = mongoose.Schema;
   var A = new Schema({
   name:String,
   });
   module.exports = mongoose.model('A', A);
  </code></pre>
  
  <p>--------b.model.js-------</p>
  
  <pre><code> 'use strict';
   var mongoose = require('mongoose'),
   Schema = mongoose.Schema;
   var a = require('../a/a.model');
   var B = new Schema({
   aid: {type:Schema.Types.ObjectId, ref:"a"},
   name:String
   });
   module.exports = mongoose.model('B', B);
  </code></pre>
  
  <p>--------queryfile.js---------</p>
  
  <pre><code> exports.all = function(req, res){
     b.find().populate("aid").exec(function (err, b) {
     if(err) {
    console.log(err);
    return handleError(res, err);
    }
    return res.status(200).json(b);
   });
  }
  </code></pre>
  
  <hr>
  
  <p>I have been trying to call <code>populate</code> but every time I am getting the above error, I tried to put <code>{}</code> condition in <code>find({})</code>. Tried to put conditions which are always true but every time the same error.</p>