Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: useConnection(connection) function #14802

Draft
wants to merge 2 commits into
base: 8.6
Choose a base branch
from

Conversation

IslandRhythms
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More testing required. Also please add TypeScript type definition and TypeScript test please

name: String
});
const Model = db.model('Test', schema);
const connection = start();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expand this test to use a different uri than db, and assert that Model.find() executes queries against the new uri rather than the old uri.

As written, I don't think that will work because on further review we'll need to also update the model's collection properties (see Model.compile())

  const collection = connection.collection(
    collectionName,
    collectionOptions
  );

  model.prototype.collection = collection;
  model.prototype.$collection = collection;
  model.prototype[modelCollectionSymbol] = collection;

delete this.db.models[this.modelName];
}
this.db = connection;
connection.models[this.modelName] = this;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to test this a bit more thoroughly, it looks like we also need to modify the model's collection as well

@vkarpov15 vkarpov15 marked this pull request as draft August 20, 2024 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants