title: Mongoose TypeError on a model's findOne method
body: <p>The following TypeError cropped up in some old code.</p>
  
  <pre><code>TypeError: Object #&lt;Object&gt; has no method 'findOne'
  </code></pre>
  
  <p>The Model that was affected recently had two new static methods defined and those methods referenced external models. After backing out the new static methods, I was able to determine the root cause to be the require statements of the external models. The pattern looks like the following:</p>
  
  <pre><code>var UserModel = require('./user');
  
  var GroupSchema = new Schema({
      name: String,
      users: [{ type : Schema.ObjectId, ref: 'UserModel'}],
  });
  
  GroupSchema.statics.findSomeUsers = function(group, callback) {
      this.find({name : session_user._id}, function(err, groups) {
          UserModel.find({_id : {$in : group.users}}, function(err,patients) {
              // do magic
          });
      });
  };
  
  module.exports = mongoose.model('GroupModel', GroupSchema);
  </code></pre>
  
  <p>There is a code fragment in the application that calls GroupModel.findOne({name:'gogo'}) that leads to the TypeError. when I remove the require statement for the UserModel in the GroupSchema, app code works again. </p>
  
  <p>Why does Javascript start to think findOne() is an instance method with the addition of the require statement?</p>