I can't quite wrap my brain around the following situation.

I have an invoice, which is a row in the table Orders. 
There are multiple items on the invoice, which are rows in table Items that are 
keyed to the order.
I want to figure out how much this order weighs.

Weights for items are stored in the table SKUs. Each item points back to a 
particular SKU. 


In Sequel, I started out by trying to do something like

        Orders[2543].items.skus.sum(:weight)

but of course that doesn't work. Then I started fiddling with 

        Orders[2543].items_dataset . . .

but reading through the documentation on associations didn't give me any idea 
where to go next. I suspect if I go back to the docs for datasets I might 
figure it out. However, when I start to feel like I'm just writing a flippin' 
SQL query, except I'm doing it in a foreign language, that's when I wonder if 
I've missed something.

Sure, I can just shove all the model crap out of the way and reach right into 
the database and make it tell me what I want to know: 
        DB['select sum(skus.weight) from orders join items on (orders.id = 
order_id) join skus on (sku_id = skus.id) where orders.id = 2543'].first

But I really like models. I just haven't figured out how to reach through a 
model's associations to the associations beyond that except by bypassing the 
whole thing and using SQL. 

        class Order < Sequel::Model
                one_to_many :items
        end
        
        class Item < Sequel::Model
                many_to_one :order
                many_to_one :sku        
        end

        class Sku < Sequel::Model
                one_to_many :items
        end


Can anybody point me in the right direction for this?

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to