diff --git a/lib/schema_associations/active_record/associations.rb b/lib/schema_associations/active_record/associations.rb index 5ff0b8c..39d5e94 100644 --- a/lib/schema_associations/active_record/associations.rb +++ b/lib/schema_associations/active_record/associations.rb @@ -80,6 +80,7 @@ def schema_associations_config # :nodoc: def _load_schema_associations_associations #:nodoc: return if @schema_associations_associations_loaded @schema_associations_associations_loaded = true + return if abstract_class? return unless schema_associations_config.auto_create? reverse_foreign_keys.each do | foreign_key | diff --git a/spec/association_spec.rb b/spec/association_spec.rb index 672925a..9d3ee1d 100644 --- a/spec/association_spec.rb +++ b/spec/association_spec.rb @@ -637,6 +637,27 @@ class OwnComment < Comment end + context "with abstract base classes" do + before(:each) do + create_tables( + "posts", {}, {} + ) + class PostBase < ActiveRecord::Base ; self.abstract_class = true ; end + class Post < PostBase ; end + end + + it "should skip abstract classes" do + expect { PostBase.table_name }.to_not raise_error + expect( PostBase.table_name ).to be_nil + expect( !! PostBase.table_exists? ).to eq(false) + end + + it "should work with classes derived from abstract classes" do + expect( Post.table_name ).to eq("posts") + expect( !! Post.table_exists? ).to eq(true) + end + end + if defined? ::ActiveRecord::Relation context "regarding relations" do