Skip to content

Commit

Permalink
Fix handling of Class.new(ModelClass){set_dataset :table} on ruby 1.8
Browse files Browse the repository at this point in the history
This was broken with the implicit table name refactoring between
4.24.0 and 4.25.0.
  • Loading branch information
jeremyevans committed Aug 17, 2015
1 parent 13cc71e commit 126b11f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD

* Fix handling of Class.new(ModelClass){set_dataset :table} on ruby 1.8 (jeremyevans)

* Use range function constructors instead of casts for known range types in pg_range (jeremyevans) (#1066)

* Make class_table_inheritance plugin work without sti_key (jeremyevans)
Expand Down
12 changes: 7 additions & 5 deletions lib/sequel/model/base.rb
Expand Up @@ -509,11 +509,13 @@ def inherited(subclass)
subclass.instance_variable_set(iv, sup_class_value)
end

if @dataset && self != Model
subclass.set_dataset(@dataset.clone, :inherited=>true) rescue nil
elsif (n = subclass.name) && !n.to_s.empty?
db
subclass.set_dataset(subclass.implicit_table_name) rescue nil
unless ivs.include?("@dataset")
if @dataset && self != Model
subclass.set_dataset(@dataset.clone, :inherited=>true) rescue nil
elsif (n = subclass.name) && !n.to_s.empty?
db
subclass.set_dataset(subclass.implicit_table_name) rescue nil
end
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/model/base_spec.rb
Expand Up @@ -91,6 +91,13 @@ class ::BootSize < ShoeSize; end
it "should raise if no dataset is explicitly set and the class is anonymous" do
proc {@b.dataset}.must_raise(Sequel::Error)
end

it "should not override dataset explicitly set when subclassing" do
sc = Class.new(::Elephant) do
set_dataset :foo
end
sc.table_name.must_equal :foo
end
end

describe Sequel::Model, "implicit table names" do
Expand Down

0 comments on commit 126b11f

Please sign in to comment.