Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

getModelForClass() does not use options in its cache; move the options somewhere else ? #186

Closed
xurei opened this issue Aug 31, 2018 · 1 comment

Comments

@xurei
Copy link

xurei commented Aug 31, 2018

The getModelForClass() function takes a GetModelForClassOptions argument, but this argument is never used in the cache mechanism.

Hence, if you call getModelForClass with different options, the cache will not notice it and the returned Model won't be the one expected.

I guess it doesn't much make sense to create two different Model from the same class. I suggest that the GetModelForClassOptions should be placed somewhere else.

The ideal thing for me would be something like this :

@modelOptions({
    existingMongoose: /* ... */, 
    existingConnection: /* ... */,
    schemaOptions: /* ... */, 
})
export class Entity extends Typegoose { /* ... */ }
export const Model = new Entity().getModelForClass(Entity); //No more option allowed here

This way, you cannot use differents options anymore on the same class and you can use getModelForClass() multiple times without fear.

The alternative would be to use the options as keys in the cache. But it seems useless from my point of view.

What do you think ? I'm willing to write a PR if this makes sense to everyone.

hasezoey referenced this issue in typegoose/typegoose Aug 5, 2019
- removes modeloptions from all functions
- adding @modeloptions for Classes
- adding test for @modeloptions
- set tslint rule "max-line-length" to warn instead of erroring

fixes szokodiakos#186
fixes hasezoey#6
@hasezoey
Copy link
Contributor

hasezoey commented Sep 2, 2019

as with version 6.0.0 model options are moved to the @modelOptions decorator

@Ben305 This can be closed

@Ben305 Ben305 closed this as completed Sep 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants