title: nodejs mongoose : cyclic dependency detected
body: <p>I'm getting a cyclic dependency exception whereas I don't find any cyclic possibility in the very simple code at this point. I'm expecting it is happening due to population between two mongoose models but as said here : <a href="https://stackoverflow.com/questions/21023089/">mongoose - possible circular dependency?</a> this shouldn't produce this kind of error so I don't understand.</p>
  
  <p>model\customer.js</p>
  
  <pre><code>var mongoose = require('mongoose'), Schema = mongoose.Schema;
  
  var customerSchema = new Schema({
    _siretCustomer:
      { type: String, required: true, minlength: 15, maxlength: 15, index: {unique: true} },
    fileNumberCustomer:
      { type: String, required: true, minlength: 6, maxlength: 6 },
    companyTypeCustomer:
      { type: String, required: true },
    companyNameCustomer:
      { type: String, required: true },
    contactName1Customer:
      { type: String, required: false, default: null },
    contactName2Customer:
      { type: String, required: false, default: null },
    landlineContact1Customer:
      { type: String, required: false, default: null },
    landlineContact2Customer:
      { type: String, required: false, default: null },
    emailContactCustomer:
      { type: String, required: false, default: null },
    obligationCommentCustomer:
      { type: String, required: false, default: null },
    taskCommentCustomer:
      { type: String, required: false, default: null },
    creationDateCustomer:
      { type: Date, default: Date.now },
    userCustomer:
     [{ type: Schema.Types.ObjectId, ref: 'User', required: true }]
  }, { collection: 'customer' });
  
  module.exports = mongoose.model('Customer', customerSchema, 'customer');`
  </code></pre>
  
  <p>model\user.js</p>
  
  <pre><code>var mongoose = require('mongoose'), Schema = mongoose.Schema;
  
  var userSchema = new Schema({
      _trigramUser:
          { type: String, required: true, index: { unique: true } },
      lastnameUser:
          { type: String, required: true },
      firstnameUser:
          { type: String, required: true },
      privilegeUser:
          { type: String, required: true, enum: ['Accountant', 'Social operator'] },
      dateCreationUser:
          { type: Date, default: Date.now  },
      passwordUser:
          { type: String, required: true },
      customersUser:
          [{ type: String, ref: 'Customer'}]
  }, { collection: 'user'});
  
  module.exports = mongoose.model('User', userSchema, 'user');
  </code></pre>
  
  <p>controller\session\customerController.js</p>
  
  <pre><code>exports.readCustomer = (req, res) =&gt; {
      database.getConnection();
      customer.find(req).populate('userCustomer').exec((err, customer) =&gt; {
      if (err) return res.status(500).json(err.stack);
      res.status(200).json(customer);
    });
  };
  </code></pre>