Realized we could get rid of the need to use the explicit table_map option
to CTI w/ a qualified dataset *if we can assume that the subclasses are
qualified the same way as the superclass*. It seems like a more reasonable
default assumption than that they are not using the same qualifier, and can
still use the table_map to get around it if needed.
I wasn't sure if this was the best way to get the superclass' qualifier,
but the following patch adds a spec and passes:
If it looks good and my assumption makes sense I'll submit a PR or make
changes.
diff --git a/lib/sequel/plugins/class_table_inheritance.rb
b/lib/sequel/plugins/class_table_inheritance.rb
index 214f50bb7..27b9be1c4 100644
--- a/lib/sequel/plugins/class_table_inheritance.rb
+++ b/lib/sequel/plugins/class_table_inheritance.rb
@@ -272,7 +272,11 @@ module Sequel
if table = cti_table_map[n.to_sym]
columns = db.from(table).columns
else
- table = subclass.implicit_table_name
+ table = if table_name.is_a?(SQL::QualifiedIdentifier) &&
schema = dataset.schema_and_table(table_name).first
+ SQL::QualifiedIdentifier.new schema,
subclass.implicit_table_name
+ else
+ subclass.implicit_table_name
+ end
columns =
check_non_connection_error(false){db.from(table).columns}
table = nil if !columns || columns.empty?
end
diff --git a/spec/extensions/class_table_inheritance_spec.rb
b/spec/extensions/class_table_inheritance_spec.rb
index d7fa347ac..3677cd53b 100644
--- a/spec/extensions/class_table_inheritance_spec.rb
+++ b/spec/extensions/class_table_inheritance_spec.rb
@@ -594,7 +594,7 @@ describe "class_table_inheritance plugin with dataset
defined with QualifiedIden
def self.columns
dataset.columns || dataset.opts[:from].first.expression.columns
end
- plugin :class_table_inheritance, key: :type,
:table_map=>{:Manager=>Sequel[:hr][:managers], :Staff=>Sequel[:hr][:staff]}
+ plugin :class_table_inheritance,
:table_map=>{:Staff=>Sequel[:hr][:staff]}
end
class ::Manager < Employee
one_to_many :staff_members, :class=>:Staff
@@ -609,6 +609,12 @@ describe "class_table_inheritance plugin with dataset
defined with QualifiedIden
[:Manager, :Staff, :Employee].each{|s| Object.send(:remove_const, s)}
end
+ it "should use a subquery with the same qualifier in subclasses" do
+ Employee.dataset.sql.must_equal 'SELECT * FROM hr.employees'
+ Manager.dataset.sql.must_equal 'SELECT * FROM (SELECT hr.employees.id,
hr.employees.name, hr.employees.kind FROM hr.employees INNER JOIN
hr.managers ON (hr.managers.id = hr.employees.id)) AS employees'
+ Staff.dataset.sql.must_equal 'SELECT * FROM (SELECT hr.employees.id,
hr.employees.name, hr.employees.kind, hr.staff.manager_id FROM hr.employees
INNER JOIN hr.staff ON (hr.staff.id = hr.employees.id)) AS employees'
+ end
+
it "should handle many_to_one relationships correctly" do
Manager.dataset = Manager.dataset.with_fetch(:id=>3, :name=>'E')
Staff.load(:manager_id=>3).manager.must_equal Manager.load(:id=>3,
:name=>'E')
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.