select

Hi, I'm trying to query all the products and their respective categories. I have a big problem, I've managed to filter as I expect, however the result has a strange format for me. If a product has 3 categories the result creates 3 identical objects with only 1 key difference and I want it to only create one object and not repeat for each category, I know that groupBy helps me, but it makes me lose information. Is there an easy way to approach this case? I've thought about doing the queries separately and adjusting everything at the end or iterating over the result and formatting it to my liking, but it's getting a bit cumbersome.
No description
5 Replies
edard3v
edard3vOP3mo ago
In the end I was able to solve it this way, but I feel strange, I feel like I did a lot of things and I don't know if it's the best way. I appreciate some feedback.
No description
edard3v
edard3vOP3mo ago
This way it works for me as I expect
No description
No description
edard3v
edard3vOP3mo ago
But if I apply a filter to bring all the products that match 1 category, it only shows that category and not the 3 that T.T has.
No description
edard3v
edard3vOP3mo ago
and this completely ignores the second where. xD
No description
edard3v
edard3vOP3mo ago
In the end I was able to achieve my goal this way, but I feel that everything is wrong or that it is bad practice.
No description

Did you find this page helpful?