Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
collection sum
Grayson Piercee
2/16/2008 2:56:00 AM
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
--
Posted via
http://www.ruby-...
.
1 Answer
Christopher Dicely
2/16/2008 7:29:00 AM
0
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).
On Feb 15, 2008 6:55 PM, Grayson Piercee <graysonpierce@yahoo.com> wrote:
> 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
> --
> Posted via
http://www.ruby-...
.
>
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
collection sum
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password