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

[3.0] has_one association reader returns Hash instead of model object #440

Closed
wpc opened this issue Aug 27, 2014 · 7 comments
Closed

[3.0] has_one association reader returns Hash instead of model object #440

wpc opened this issue Aug 27, 2014 · 7 comments
Milestone

Comments

@wpc
Copy link

wpc commented Aug 27, 2014

Found this on 3.0.0.alpha.11 with Cypher session type.

class Request
  include Neo4j::ActiveNode
  property :url
  has_one :out, :next, :model_class => "Request"
end

def test_next
   Neo4j::Transaction.run do
      req1 = Request.create(:url => "/foo")
      req2 = Request.create(:url => "/bar")
      req1.next = req2
      assert_equal req2, req1.next
   end
end

  1) Failure:
RequestTest#test_next
--- expected
+++ actual
@@ -1 +1 @@
-#<UserRequest url: "/foo">
+{"url"=>"/foo"}

Hope this is helpful.

@andreasronge
Copy link
Member

Thanks. Yes there are limitations using transactions together with the Neo4j server. I will add this to the documentation. We can probably solve this if models uses id_property (a user defined primary key) since the neo4j server does not return the neo4j ids inside transactions.

@andreasronge andreasronge added this to the 3.1.0 milestone Aug 27, 2014
andreasronge added a commit that referenced this issue Aug 27, 2014
@wpc
Copy link
Author

wpc commented Aug 27, 2014

Thanks for the suggestion. I will try use id_property

@wpc wpc closed this as completed Aug 27, 2014
@andreasronge
Copy link
Member

id_property will not solve your problem, but maybe you can do a workaround using the id which is available in the hash response. Yes, this is very awkward and might not solve your problem.
Hopefully we will have a solution for this in 3.1

@wpc
Copy link
Author

wpc commented Aug 27, 2014

At least I can use the id to find back node and provide a wrapper to the association method, right? Something in my mind:

alias :old_next :next
def next
   record = old_next
   Hash === record ? [find model by record's id property] : record
end

Or are you saying it is not even possible to read the node back once in transaction?

@wpc
Copy link
Author

wpc commented Aug 27, 2014

Sorry I accidentally close this. I guess you want to keep this issue open for 3.1.0 milestone.

@wpc wpc reopened this Aug 27, 2014
@andreasronge
Copy link
Member

Hmm, looks the workaround I was thinking of was not working.

Did a test and neo4j-core complained. I will investigate.

class FooPerson
  include Neo4j::ActiveNode
  id_property :uuid, auto: :uuid
  property :name
  has_one :out, :next, model_class: self
end

def test
  f1 = FooPerson.create name: 'f1'
  f2 = FooPerson.create name: 'f2'
  f1.next = f2
  n = f1.next
  id = n['uuid']
  puts "F1 #{n.inspect} id #{id}"
  nodes = Neo4j::Label.find_nodes(FooPerson.name, :uuid, id).to_a
  puts "FOUND #{nodes.inspect}"
end

Neo4j::Transaction.run { test }

andreasronge added a commit to neo4jrb/neo4j-core that referenced this issue Aug 27, 2014
@subvertallchris
Copy link
Contributor

Realize this one is pretty old but all issues related to working within transactions should be resolved as of 3.0.1. @wpc please let me know if you're still having any trouble.

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

3 participants