collection sum

G

Grayson Piercee

Hello,

I really like the ability to do sums right in the object model, for
example

@items.sum:)unit_price), etc! works great!

However I wonder how you step down through an association to do a sum

current_user.carts.first.cart_items.items.sum:)unit_price)

Finding the users first cart works fine but the collection to collection
between cart_items to items doesn't.

TIA

GP
 
C

Christopher Dicely

This sounds like a Rails question, and you may want to ask it on a
Rails-specific list; also, its hard to tell what may be going on
without knowing the definition of the objects being used. With the
most intuitive layout of objects for what you seem to be doing, I'd
expect what you are looking for to be something like
current_user.carts.first.items.sum:)unit_price).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,480
Latest member
CrazyMember

Latest Threads

Top