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

Models with the same name #400

Open
rjkz808 opened this issue Feb 24, 2021 · 1 comment
Open

Models with the same name #400

rjkz808 opened this issue Feb 24, 2021 · 1 comment

Comments

@rjkz808
Copy link

rjkz808 commented Feb 24, 2021

When creating several classes with the same name AND applying typegoose's modelOptions for them this way:

// ----
// a.ts
// ----
@modelOptions({ options: { customName: 'A' }, schemaOptions: { collection: 'a' } })
export class Schema {}

// ----
// b.ts
// ----
@modelOptions({ options: { customName: 'B' }, schemaOptions: { collection: 'b' } })
export class Schema {}

// --------------
// some.module.ts
// --------------
import * as A from './a';
import * as B from './b';

@Module({
  imports: [TypegooseModule.forFeature([A.Schema, B.Schema])]
})
export class SomeModule {}

// ---------------
// some.service.ts
// ---------------
import * as A from './a';
import * as B from './b';

@Injectable()
export class SomeService {
  constructor(
    // Skipping some types to make this example simpler
    @InjectModel(A.Schema) private aModel: any,
    @InjectModel(B.Schema) private bModel: any,
  ) {}

  onModuleInit() {
    // Both output either 'A' or 'B'
    console.log(this.aModel.modelName);
    console.log(this.bModel.modelName);
  }
}

nestjs-typegoose injects the same model twice, seems like it ignores options.customName value for some reason.
Are there any plans to support this case? Thank you.

@kpfromer
Copy link
Owner

Yeah, you are correct. The current implementation does not honor the customName from typegoose. It internally uses the class name, and thus you get a naming collision.

Are there any plans to support this case?

I think that honoring typegoose's customName is important (I did not know about it until now). But I am quite busy at the moment with classes. So a PR would be much appreciated!

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

No branches or pull requests

2 participants