Start from a fresh Todo tutorial app.
Let's say you want to have subtasks in big tasks, and want to create child-parent Todos.
Use the cli to create the relation between Todo and Todo. At least belongsTo and hasMany will create the error, but others certainly will as well.
Code generated cannot start, with these messages:
src/models/todo.model.ts(6,9): error TS2395: Individual declarations in merged declaration 'Todo' must be all exported or all local.
src/models/todo.model.ts(6,9): error TS2440: Import declaration conflicts with local declaration of 'Todo'.
src/models/todo.model.ts(13,14): error TS2395: Individual declarations in merged declaration 'Todo' must be all exported or all local.
src/repositories/todo.repository.ts(9,9): error TS2395: Individual declarations in merged declaration 'TodoRepository' must be all exported or all local.
src/repositories/todo.repository.ts(9,9): error TS2440: Import declaration conflicts with local declaration of 'TodoRepository'.
src/repositories/todo.repository.ts(11,14): error TS2395: Individual declarations in merged declaration 'TodoRepository' must be all exported or all local.
src/controllers/todo-todo.controller.ts(19,3): error TS2300: Duplicate identifier 'Todo'.
src/controllers/todo-todo.controller.ts(20,3): error TS2300: Duplicate identifier 'Todo'.
To work, without these messages.
These errors happen because the CLI blindly appends the imports to each files. The Todo model declaration file tries to import its own definition, same thing happens with the repository. The controller that handles the relation imports both related models, but since they are the same, it tries to import it twice!
_See Reporting Issues for more tips on writing good issues_
@Salketer, would this docs https://loopback.io/doc/en/lb4/BelongsTo-relation.html#handling-recursive-relations help?
cc @agnes512
Thank you @dhmlau this may help some people facing the issue.
There is indeed a little subtlety that is pointed out in the doc you are showing, yes. But the CLI should not create bad code, that is counter productive...
PS: Sorry for late reply, the loopback.io wasn't working when you replied...