i am using the Loopback4 framework. I try to inject a repository into some model class (documentRepository into userModelClass). I am not sure if it is possible to do something like that. The reason why i want to do this is because in the repository i have a method which returns all documents that are assigned to an user. Later there will be more models which have to use the same method.
This is the way i tried to inject my repository (constructor user model):
constructor(
data?: Partial<User>,
@repository(DokumentRepository) public dokumentRepository?: DokumentRepository
)
When i am starting the application i am getting the following error in my console:
E:\workspace\compass\backend\node_modules\@loopback\repository\dist\decorators\repository.decorator.js:51
const stringOrModel = typeof modelOrRepo !== 'string' && !modelOrRepo.prototype.getId
^
TypeError: Cannot read property 'prototype' of undefined
at Object.repository (E:\workspace\compass\backend\node_modules\@loopback\repository\dist\decorators\repository.decorator.js:51:75)
at Object.<anonymous> (E:\workspace\compass\backend\dist\src\models\admin\user.model.js:266:29)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (E:\workspace\compass\backend\dist\src\repositories\admin\user.repository.js:19:22)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
Waiting for the debugger to disconnect...
Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)
Maybe someone of you have an idea how to inject a repository to a model or can tell my why that is not possible...