Skip to content

Commit

Permalink
Merge pull request #13 from dmeranda/master
Browse files Browse the repository at this point in the history
Don't try to load associations for abstract base classes.
  • Loading branch information
ronen committed Nov 15, 2015
2 parents 6a965e2 + 933b047 commit 10d7b06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/schema_associations/active_record/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
21 changes: 21 additions & 0 deletions spec/association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 10d7b06

Please sign in to comment.