loopback.findModel method returns undefined
Hello. I have two models person and post. When I'm trying to get post model in person model for their events subscription I'm getting undefined value.
var Post = loopback.findModel('post');
Here is my model-config.json
...
"person": {
"dataSource": "db",
"public": true
},
"post": {
"dataSource": "db",
"public": true
},
...
Can you explain please why does it happen?
As per the documentation here : https://apidocs.strongloop.com/loopback/#loopback-findmodel-1 . It is stated that it looks up a model class by name from all models created by loopback.createModel(). So, I think it doesn't work for models created by loopback cli. And hence should rather use "app.models" to get the model as described here : https://apidocs.strongloop.com/loopback/#app-models
Where are you doing this lookup? All datasources and models need to be properly attached before you can run it. Hence, you cannot run it directly in the body of your models customization method.
Hi @dmitrovskiy , would you please provide the information of where you write your code var Post = loopback.findModel('post'); like the path of your file or the folder contains it.
I am closing it since info provided is not enough to reproduce the issue. If anyone run into similar issue or could provide more details, please feel free to reopen it:) Thanks for understanding.