LearnBoost/mongoose — pull request #2197 by yamadapc (2014-07-16 14:04:21+00:00)
Title: Fix `mongoose.models` consistency bug.

Since `mongoose.models` and `mongoose.connection.models` weren't the
same object, calling `doc.db.modelNames()` didn't return the same output
even if `doc` was an instance of a `Model` registered to the default
connection.

This caused weird problems when using discriminators, since they are
registered with `parentModel.db.model(...)` (which is equal to
`mongoose.connection`) rather than with `mongoose.model(...)`. Using
discriminators, `mongoose.models` ended up having the parent models'
references, while `mongoose.connection.models` had the discriminators
references.

The fix was to set the default connection's `models` property to
`mongoose.models` so that they share the same object. This makes
`mongoose.models` and `mongoose.connection.models` (or
`document.db.models`, `model.db.models`, `model.base.models` etc.)
deterministically equal.