Skip to content

Commit

Permalink
Merge pull request #765 from neo4jrb/inherited_association_attributes
Browse files Browse the repository at this point in the history
associations_keys should inherit, fixes #763
  • Loading branch information
subvertallchris committed Apr 20, 2015
2 parents f17f879 + 8e0153e commit c46abb5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/neo4j/active_node/has_n.rb
Expand Up @@ -96,12 +96,13 @@ def associations
end

def associations_keys
@associations_keys ||= []
@associations_keys ||= associations.keys
end

# make sure the inherited classes inherit the <tt>_decl_rels</tt> hash
def inherited(klass)
klass.instance_variable_set(:@associations, associations.clone)
@associations_keys = klass.associations_keys.clone
super
end

Expand Down
9 changes: 9 additions & 0 deletions spec/e2e/inheritance_spec.rb
Expand Up @@ -16,6 +16,7 @@
property :specs # Hash
index :name
serialize :specs
has_many :out, :models, model_class: false
end

stub_named_class('Car', Vehicle) do
Expand Down Expand Up @@ -71,4 +72,12 @@
expect(toyota.specs.class).to eq Hash
end
end

describe 'associations' do
it 'are inherited' do
expect(Car.new).to respond_to(:models)
expect(Vehicle.associations_keys).to include(:models)
expect(Car.associations_keys).to include(:models)
end
end
end

0 comments on commit c46abb5

Please sign in to comment.