When using a STI base class to eager loading a relationship (via a
join) with similar keys, STI creates a query with an ambiguous
discriminator column.

class Person < Sequel::Model(:Person)
  plugin :single_table_inheritance :Type
  set_primary_key [ :Id, :Type ]
  #has one :badge
end

class Badge < Sequel::Model(:Badge)
  set_primary_key [ :Id, :Type ]
end

You can't qualify the discriminator column via:
plugin :single_table_inheritance :Person__Type
because subclass will not be loaded by the Person dataset's row_proc.
Actually this leads to calling constantize() on an empty String, which
returns an Object, which causes an error:

>From the plugin:

 def self.configure(model, key)
        m = model.method(:constantize)
        model.instance_eval do

          #:Person__Type
          @sti_key = key
          @sti_dataset = dataset

          #key doesn't exist, calls Object.load()
          dataset.row_proc = lambda{|r| (m.call(r[key]) rescue
model).load(r)}
        end
  end


Here's a patch that qualifies the column before creating the subclass'
dataset filter:
http://pastie.org/822659.txt

-Skye


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