You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to do referencesmany in loopback 4 to populate relational model data ? #7102
I wanted to store categories and its products Ids as an array in the collection. On get method I need show category info as well as product details as mentioned below .Is there any best with relational model in loopback? I am new in Loopback and node js, please suggest best practice.
Can you provide and example, I had spend almost three weeks in your documentation and couldn't able to figure it out, you could have include this kind of one sample in you shopping cart examples. Is it possible to use hasMany without using belongsTo in the target model
In your example source model’s id as the foreign key property (customerId) in the target model. But in my case I don't have any relation with category white creating the product. When I create a category I will be adding products Ids as array in to it. When I access category I need to populate product detail as well. Is there any way to do it without foreign key property in the target model?
Activity
JerryHuang2015 commentedon Feb 19, 2021
https://loopback.io/doc/en/lb4/Relations.html
noufalnoufu commentedon Feb 20, 2021
Can you provide and example, I had spend almost three weeks in your documentation and couldn't able to figure it out, you could have include this kind of one sample in you shopping cart examples. Is it possible to use hasMany without using belongsTo in the target model
JerryHuang2015 commentedon Feb 21, 2021
it is very clear on loopback 4,
@hasMany(() => Order) orders?: Order[];1st check your Loopback version
one to many relation https://loopback.io/doc/en/lb4/HasMany-relation.html
many to many relations https://loopback.io/doc/en/lb4/HasManyThrough-relation.html
noufalnoufu commentedon Feb 21, 2021
In your example source model’s id as the foreign key property (customerId) in the target model. But in my case I don't have any relation with category white creating the product. When I create a category I will be adding products Ids as array in to it. When I access category I need to populate product detail as well. Is there any way to do it without foreign key property in the target model?
noufalnoufu commentedon Feb 23, 2021
{
"@loopback/authentication": "^4.2.5",
"@loopback/authentication-jwt": "^0.3.1",
"@loopback/boot": "^2.3.1",
"@loopback/context": "^3.8.1",
"@loopback/core": "^2.7.0",
"@loopback/openapi-v3": "^3.4.1",
"@loopback/repository": "^2.5.1",
"@loopback/rest": "^5.0.1",
"@loopback/rest-explorer": "^2.2.2",
"@loopback/service-proxy": "^2.3.0",
"@types/bcryptjs": "^2.4.2",
"@types/lodash": "^4.14.152",
"bcryptjs": "^2.4.3",
"isemail": "^3.2.0",
"jsonwebtoken": "^8.5.1",
"loopback-connector-mongodb": "^5.5.0",
"loopback-connector-mysql": "^5.4.3",
"tslib": "^1.10.0"
}
This is my application version. I have found solution for my issue in lb3
https://loopback.io/doc/en/lb3/Embedded-models-and-relations.html#referencesmany
I am looking for same thing in lb4. Please help me, my entire application development got stuck here, other wise I have to switch to core node and express.