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

InjectModel from other module #1

Closed
scopsy opened this issue Jan 2, 2018 · 2 comments
Closed

InjectModel from other module #1

scopsy opened this issue Jan 2, 2018 · 2 comments

Comments

@scopsy
Copy link

scopsy commented Jan 2, 2018

I have two models imported to ApplicationModule:

  • AuthModule
  • UserModule
@Module({
    imports: [
        MongooseModule.forRoot(process.env.DB_URL),
        UsersModule,
        AuthModule
    ],
    controllers: [AppController],
    components: []
})
export class ApplicationModule {}
@Module({
    imports: [
        MongooseModule.forFeature([{
            name: 'User',
            schema: UserSchema
        }]),
        forwardRef(() => AuthModule)
    ],
    components: [],
    controllers: [UsersController],
    exports: []
})
export class UsersModule {
}

Inside the AuthModule I need to be able to access the UserSchema model, but im getting:

Error: Nest can't resolve dependencies of the AuthService (?). Please verify whether [0] argument is available in the current context.

when trying to use @InjectModel(UserSchema).

What am i missing?

@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Jan 13, 2018

Hi @scopsy,
You have to export this module as well:

MongooseModule.forFeature([{
   name: 'User',
   schema: UserSchema
 }]),

@scopsy
Copy link
Author

scopsy commented Jan 14, 2018

@kamilmysliwiec That's what i ended doing. Thanks.

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