Trying things out, <name of association>_dataset gets me what I want.
Is that the way one_to_many is supposed to work? (if you only have
read access to a legacy DB)

orders = Order.all
orders.each do |r|
   items = r.items_dataset
   items.all.each do |i|
      ... do something with this item
   end
end


On Sep 1, 7:31 am, mjskier <[email protected]> wrote:
> I'm trying to get up to speed on sequel but I'm not having much luck
> with the mechanics of the one_to_many association. Thanks for any
> insight you might provide:
>
> I'm trying something like this (using a legacy MS SQL database)
>
> class Order < Sequel::Model(:Order)
>   one_to_many :items, :key => :Order, :class => :OrderItem
> end
>
> class OrderItem < Sequel::Model(:OrderItem)
>   many_to_one :order, :key => :Order, :class => :Order
> end
>
> Table Order doesn't have a OrderItem column, which I think is pretty
> common for these kind of situations. If you wanted to find all the
> items for an order you'd have to query all items whose order key match
> a specific order.
>
> On to the part I don't understand: Who populates Order.items for a
> specific Order: The association, or do I need to add code to do so?
>
> The following code shows that items is an empty array (and my log
> doesn't show any query for the items)
>
> orders = Order.all
> orders.each do |r|
>   items = r.items
>   puts "items is a #{items.class}"
>   pp items
> end

-- 
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