Count SaleItems sold by Product ID
Hello, I have a Sales Resource with (hasMany) SaleItems Resource which selects a product to sell from the Product table. I'm looking to have a column in my Product table that sums all the related product sales to give a Sold total.
I've read through the docs and finding this particular issue to be a little tricky. Any help is appreciated!
8 Replies
migrations
![No description](https://answer-overflow-discord-attachments.s3.amazonaws.com/1224803952512602132/Screenshot_2024-04-02_at_3.32.38_PM.png)
![No description](https://answer-overflow-discord-attachments.s3.amazonaws.com/1224803952802140180/Screenshot_2024-04-02_at_3.32.45_PM.png)
![No description](https://answer-overflow-discord-attachments.s3.amazonaws.com/1224803953129164920/Screenshot_2024-04-02_at_3.32.59_PM.png)
product table?
![No description](https://answer-overflow-discord-attachments.s3.amazonaws.com/1224804951562387556/Screenshot_2024-04-02_at_3.37.12_PM.png)
I think you should create an attribute and count the sum there
Thank you @krekas, I'll look into that!
Take a look at
withSum
And please dont use decimal/floats for currency values
And next time please use real code and not images πThanks @dissto! Sorry!
@dissto From what I'm seeing, withCount will count the amount of relationships, right?
Yes, but I wrote to take a look at
withSum
not withCount
πHaha, oops! Thank you