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

Declared has_list().to() does not produce the reciprocal has_one().from() #3

Closed
ghost opened this issue Feb 5, 2010 · 9 comments
Closed

Comments

@ghost
Copy link

ghost commented Feb 5, 2010

This short script illustrates the problem that (I think) is happening with has_list. Replacing that call with has_n makes the code work as expected.

    require 'rubygems'
    require 'neo4j'

    class B
      include Neo4j::NodeMixin
    end

    class A
      include Neo4j::NodeMixin
      has_list(:a2b).to(B)
    end

    class B
      has_one(:b2a).from(A, :a2b)
    end

    Neo4j::Transaction.run do
      a = A.new
      b = B.new
      a.a2b << b

      if b.b2a == a
        puts "It works!"
      else
        puts "It does not work!"
      end
    end
@andreasronge
Copy link
Member

Using a has_list and has_one will never work together, one is for outgoing relationships and the other for one relationship with linked list.
However, it would be really cool if th following example works.
class A
include Neo4j::NodeMixin
has_list :a2b
end

class B
has_list(:b2a).from(A)
end

I guess it does not work - have never tried.

@andreasronge
Copy link
Member

It should be
class B
has_list(:b2a).from(A, :a2b)
end

@ghost
Copy link
Author

ghost commented Feb 6, 2010

You are right, of course. I got the impression that has_list was just has_n with an order parameter, but Neoclipse tells me otherwise. Thanks, and sorry for raising an issue about it.

@ghost
Copy link
Author

ghost commented Feb 6, 2010

In an almost related comment; assigning a node to a has_one relationship does not delete the previous relationship. This does not seem to me like the behaviour most people would expect, but again, I'm new to the library. As an example, the following script prints "1 2", whereas simply "2" might be more intuitive:

require 'rubygems'
require 'neo4j'

class B
  include Neo4j::NodeMixin
  property :name
end

class A
  include Neo4j::NodeMixin
  has_one(:a2b).to(B)
end

Neo4j::Transaction.run do
  a = A.new
  b1 = B.new(:name => '1')
  b2 = B.new(:name => '2')
  a.a2b = b1
  a.a2b = b2

  puts a.a2b.name
  a.a2b_rel.del
  puts a.a2b.name
end

@andreasronge
Copy link
Member

Yes, you are right. I'm not sure what the expected behaviour would be.
Should it be a more functional way - you could only assign it once or a get an exception, or should we allow to assign it several times. If the assign it several times should we then delete the old relationship - hmm

@andreasronge
Copy link
Member

Funny last sentance ... - If we reassign the relationship what should happen with the old relationship - should it get deleted ?

@ghost
Copy link
Author

ghost commented Feb 8, 2010

I think it should be deleted without throwing an exception. If the current state is node polygamy, throwing an exception would be like forbidding divorce. Seems more natural to me just to let the node replace one relationship with the other. My code is currently using this for has_one assignments:

while rel = a.a2b_rel
  rel.del
end
a.a2b_rel = new_partner_node

@ghost
Copy link
Author

ghost commented Feb 8, 2010

Cool. Thanks!

This issue was closed.
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