multiple connections and models with dots#11
Open
rosshinkley wants to merge 5 commits intojraede:masterfrom
Open
multiple connections and models with dots#11rosshinkley wants to merge 5 commits intojraede:masterfrom
rosshinkley wants to merge 5 commits intojraede:masterfrom
Conversation
Owner
|
Looks great - I'll take a look over the next few days and probably make this the next major release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Not entirely sure this is the direction the base library should go in, but I thought I'd at least share changes I had to make during some recent projects.
multiple connections
The base library did not support non-default connections (eg, connections created using
mongoose.createConnection). To correct that, the bulk of the functionality has been wrapped up insetupthat takes the connection and delimiter, both optional.This introduces breaking changes, as
require(mongoose-multitenant)('delimiter')will no longer work. Instead, the usage would look more like:I've updated the readme where appropriate to reflect this change.
model names with dots
The @watnotte changes work great with tenants that have dots in their names. However, mongo (and consequently, mongoose) allows for dots in the collection and model names, respectively. This changeset changes the behavior such that collection/model names with dots are also okay, so long as you either 1) add the tenant explicitly using
connection.mtModel.addTenant(tenantId)or 2) if the model is added to the tenant explicitly, egvar fooclass = mongoose.mtModel('tenant1.something', 'model.name'). The documentation has not been updated to reflect this, as I think it should Just Work (tm). However, I added tests to ensure both behaviors are supported, as well as the original default behavior of the last dot part being used as the model name.gruntfile changes
As a consequence of being able to add multiple connections, the
dropTestDbgrunt task had to be modified to drop all of the test databases the multitenant tests now create.I think that's everything. Feedback welcome.