activegraph
activegraph copied to clipboard
`some_node.some_association.create!` does not build the some_association relationship
Calling the create!
method on a has_many association creates the corresponding node, but does not set up the relationship between the original node and the newly created one.
Note: I have only tested this with has_many associations, but it may apply to has_one as well.
Code example
class Author
include ActiveGraph::Node
property :name, String
has_many :out, :books, model_class: 'Book', type: 'wrote'
end
class Book
include ActiveGraph::Node
property :title, String
has_one :in, :author, model_class: 'Author', origin: :books
end
a = Author.create! name: 'Karl Marx'
b = a.books.create! title: 'Das Kapital'
puts a.books.length # 0
puts b.author # nil
I would expect that this would work more like ActiveRecord, and the (a)-[:wrote]->(b)
relationship would be added to neo4j as well.
Workaround
b = a.books.create! title: 'Das Kaptial', author: a
works as expected.
Runtime information:
versions:
activegraph (10.1.0)
neo4j-ruby-driver (1.7.4)
activesupport (6.1.3)
ruby 3.0.0 (mri)
neo4j: 4.0.0