Closed jaesam closed 3 years ago
Where is UserService
provided? Is that actually registered somewhere? I assume the UsersModule
but can you paste that module definition?
Second question: do you have User extends BaseModel
somewhere?
yup the user module is pretty much directly from the starter:
import { Module } from '@nestjs/common';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
@Module({
exports: [UsersService],
controllers: [UsersController],
providers: [UsersService],
})
export class UsersModule {}
As for the second question, no I thought putting the custom base model to the option "Model" would do the similar job. Do I need to change my user model to extend the base model? what does the option "Model" actually mean?
Ok then that is your issue. Yes, you need to extend your base model. The Nest integration can't do that cleanly because I would have to be binding to something every-time you registered a model - which raises a question, with multiple connections how would I know what to connect to? It would just increase the API surface area with no real gain since extending from different bases solves that problem already.
The option for model will do the work of actually binding Knex to Objection since that has to be done during the nest initialization process. I essentially coordinate all that work for you so you don't have to.
Under the hood, it's all Objection. Objection knows what connection to use and how to query based on the superclass so you need to follow normal Objection rules for that.
The option for model will do the work of actually binding Knex to Objection since that has to be done during the nest initialization process. I essentially coordinate all that work for you so you don't have to.
Got it! and got my app to work. Thanks for the help and the package!
Thanks! Glad I could help.
Hi, I cannot wrap my head around how the model binding is done with the package.
I am getting this error:
This is my database module:
And this is my App module:
And here is my user service:
I have read the docs over and over but couldn't figure out how to bind the model properly. I have tested my code with KNEX_CONNECTION and it worked just fine so I know there is an issue with model binding. So could you please share not only the snippets but the example repo you got the code snippets from? It will definitely help users understanding how to use the package much better.