Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is corresponding method to do referencesmany in lb4 #4346

Closed
noufalnoufu opened this issue Feb 18, 2021 · 2 comments
Closed

What is corresponding method to do referencesmany in lb4 #4346

noufalnoufu opened this issue Feb 18, 2021 · 2 comments
Labels

Comments

@noufalnoufu
Copy link

noufalnoufu commented Feb 18, 2021

Can you explain how to do referencesmany in loopback 4

https://loopback.io/doc/en/lb3/Embedded-models-and-relations.html#referencesmany

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.

Category
{
"id": "1",
"Category": "Category 1",
"products": [
"1",
"2"
]
},
{
"id": "2",
"Category": "Category 2",
"products": [
"2",
"3"
]
}

Products
{
"id": "1",
"title": "Product 1"
},
{
"id": "2",
"title": "Product 2"
},
{
"id": "3",
"title": "Product 3"
}

Result
{
"Category": "Category 1",
"products": [
{
"id": "1",
"title": "Product 1"
},
{
"id": "2",
"title": "Product 2"
}
]
},
{
"Category": "Category 2",
"products": [
{
"id": "2",
"title": "Product 2"
},
{
"id": "3",
"title": "Product 5"
}
]
}

@achrinza
Copy link
Member

@dhmlau I don't permissions to shift this issue to the LoopBack 4 repo. Could you please assist? Thanks

@dhmlau
Copy link
Member

dhmlau commented Feb 20, 2021

I think it's a duplicate of loopbackio/loopback-next#7102. So I'm closing this issue as duplicate and let's continue the discussion over there. Thanks.

@dhmlau dhmlau closed this as completed Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants