F
Filamentβ€’3mo ago
smoothtire

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
smoothtire
smoothtireβ€’3mo ago
migrations
No description
No description
No description
smoothtire
smoothtireβ€’3mo ago
product table?
No description
krekas
krekasβ€’3mo ago
I think you should create an attribute and count the sum there
smoothtire
smoothtireβ€’3mo ago
Thank you @krekas, I'll look into that!
dissto
disstoβ€’3mo ago
Take a look at withSum And please dont use decimal/floats for currency values And next time please use real code and not images πŸ˜‹
smoothtire
smoothtireβ€’3mo ago
Thanks @dissto! Sorry! @dissto From what I'm seeing, withCount will count the amount of relationships, right?
dissto
disstoβ€’3mo ago
Yes, but I wrote to take a look at withSum not withCount πŸ˜‹
smoothtire
smoothtireβ€’3mo ago
Haha, oops! Thank you