On Sep 1, 6: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
You shouldn't have an association named the same as the foreign key,
even if they just differ in case.
> 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
My case is you didn't change the identifier_input_method and
identifier_output_method:
DB.identifier_input_method = nil
DB.identifier_output_method = nil
Try setting those and see if it has an effect.
The reason I think it is failing is that by default, sequel
uses :upcase for the identifier_input_method and :downcase for
the :identifier_output_method on MSSQL. Since you are using CamelCase
identifiers, you definitely don't want that.
Jeremy
--
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.