title: Mongoose model as an ES6 class with inheritance chain
body: <p>I was trying to create a ES6 class hierarchy to implement a caching layer between mongoose and mongodb queries. I saw this PR <a href="https://github.com/Automattic/mongoose/pull/4668" rel="nofollow noreferrer">https://github.com/Automattic/mongoose/pull/4668</a> and based on that wrote the below code.</p>
  
  <pre><code>'use strict'
  
  const mongoose = require('mongoose');
  mongoose.connect("mongodb://host:port/db", {});
  mongoose.connection.on('error', console.error.bind(console, 'DB connection failed', arguments));
  mongoose.connection.once('open', console.log.bind(console, 'Connected to DB'));
  
  class Base extends mongoose.Model {
      save() {
          console.log('Base class save()')
          return super.save();
      }
  
      findOne(query){
          console.log('Base class find...');
          return super.findOne(query);
      }
  }
  
  class Derived extends Base{
      save(){
          console.log('Derived class save()');
          super.save();
      }
  
      static getOne(){
          console.log('Derived class Get one');
          return this.findOne({});
      }
  }
  
  let usersSchema = new mongoose.Schema({ name: String })
  
  usersSchema.loadClass(Derived);
  
  let User = mongoose.model(Derived, usersSchema, 'users');
  
  setTimeout(function(){
      User.getOne()
              .then(user =&gt; console.log('Found user...', user));
  
      let newUser = new User();
      console.log('newUser instance of Derived ? ', (newUser instanceof Derived));
      console.log('newUser instance of Base ? ', (newUser instanceof Base));
      newUser.name = 'Tony';
      newUser.save()
                  .then(result =&gt; console.log('Saved', result));
  }, 2000);
  </code></pre>
  
  <p>Since the methods are overridden in the derived class, I was expecting the calls to the methods in Derived class will in turn call the Base class and then I could add additional logic in Base class before / after queries. </p>
  
  <p>Below is the output which I am getting, which indicates that the method invocations are not hitting the Derived/Base class. </p>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Connected to DB
  Derived class Get one
  newUser instance of Derived ?  true
  newUser instance of Base ?  true
  Base class save()
  Found user... { _id: 58ec765f9dd99f049c2a833b, name: 'Tony', __v: 0 }
  </code></pre>
  
  <p>When I call the save method, it does not hit the <em>Derived</em> class and when I call the getOne static method in <em>Derived</em> class, the call does not hit the findOne method in <em>Base</em> class. I am not sure where am I going wrong. Can anyone throw some light on this.</p>