Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some_node.some_association.create! does not build the some_association relationship #1649

Open
yourpalal opened this issue Mar 15, 2021 · 0 comments

Comments

@yourpalal
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant