neoid-gem / neoid

Extend Ruby on Rails ActiveRecord with Neo4j nodes. Keep RDBMS and utilize the power of Neo4j queries.
MIT License
171 stars 33 forks source link

0.0.51 to 0.1.2 self-referential relationship breaks #15

Open curlyice opened 11 years ago

curlyice commented 11 years ago

When I upgraded I began experiencing an issue with a self-referential relationship where in the relationship in my Postgres database would appear, but would not in Neo4j.

class User < ActiveRecord::Base
  has_secure_password
  attr_accessible :bio, :email, :first_name, :last_name, :password, :password_confirmation

  include Neoid::Node
  has_many :follows
  has_many :reverse_follows, foreign_key: :following_id, class_name: "Follow"
  has_many :followers, through: :reverse_follows, source: :user
  has_many :followings, through: :follows
end

class Follow < ActiveRecord::Base
  include Neoid::Relationship
  attr_accessible :user_id, :following_id
  belongs_to :following, class_name: "User"
  belongs_to :user

  neoidable do |c|
    c.relationship start_node: :user, end_node: :following, type: :follows
  end
end

To recreate:

  1. create a user1 and a user2
  2. user1.followings << user2
  3. save user1
  4. user2.followings << user1
  5. save user2

In 0.0.51 this behaves as expected: Screen Shot 2013-01-15 at 12 12 35 PM

In 0.1.2 only one relationship is created: Screen Shot 2013-01-15 at 12 25 20 PM

I've tried it with per model indexing both on and off, just to be sure, with the same result. Is there some other change I'm missing?

Also; this might not be the appropriate place for this, but thanks a million for your work elado.

BenMorganIO commented 10 years ago

Can you provide me the version of Neo4j that you are using?