loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

lb4 relation doesn't find models

Open danysz opened this issue 2 years ago • 5 comments

Describe the bug

I have a project with a lot of models. I organized the models in "sub directories" inside "models" directory. The "export" is working properly and all the project is working. What is not working is the possibility to add repositories, relations or anything else "lb4 relation" stops with an error "Generation is aborted: Error: No models found in ".../src/models"." I expect the script to be capable to look for models also inside according to what is available in "index.ts" from "models" directory.

Logs

No response

Additional information

No response

Reproduction

https://github.com/danysz/demo-lb4-cli-model-not-found

danysz avatar Jun 13 '23 11:06 danysz

This is the error that the CLI gives:

$ lb4 relation
? Please select the relation type belongsTo

No change to package.json was detected. No package manager install will be executed.
Generation is aborted: Error: No models found in C:\Users\Ben\Documents\dev\sandbox\demo-lb4-cli-model-not-found\src\models.
        Please visit https://loopback.io/doc/en/lb4/Model-generator.html for information on how models are discovered      

Visiting the page provided doesn't actually give any information about how models are discovered.

benjaminrae avatar Jun 15 '23 07:06 benjaminrae

This is the error that the CLI gives:

$ lb4 relation
? Please select the relation type belongsTo

No change to package.json was detected. No package manager install will be executed.
Generation is aborted: Error: No models found in C:\Users\Ben\Documents\dev\sandbox\demo-lb4-cli-model-not-found\src\models.
        Please visit https://loopback.io/doc/en/lb4/Model-generator.html for information on how models are discovered      

Visiting the page provided doesn't actually give any information about how models are discovered.

Exactly and even more there Is no way I can make it to look in the subdirectories. Which means that if I am using 100 models for different purposes all of them should be in the same directory.

danysz avatar Jun 15 '23 08:06 danysz

@loopback/boot is able to find artifacts in nested folders. I wonder if same type of artifact discovery could be used for @loopback/cli to find models/repositories in nested folders.

benjaminrae avatar Jun 15 '23 10:06 benjaminrae

I confirm lb4 is not able to find models in subdirectory. Not really a bug, but a nice to have feature.

arnaud16571542 avatar Jul 09 '23 13:07 arnaud16571542

I confirm lb4 is not able to find models in subdirectory. Not really a bug, but a nice to have feature.

It could definitely make organization a lot easier as a service grows.

benjaminrae avatar Jul 10 '23 08:07 benjaminrae