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

Error with method 'neo_id' #42

Open AlvesJonas opened 8 years ago

AlvesJonas commented 8 years ago

I have a project in Ruby 2.2.4 with Rails 4.1.2 in which want to implement a new feature to allow users to connect with other users, so I will keep my database in Postgress (using ActiveRecords) with Neoid. I followed all the steps of https://github.com/neoid-gem/neoid documentation, but when I try to save a user has returned the following error:

NoMethodError (undefined method `neo_id 'for # <Hash: 0x0000000a4542a0>)

I have created a new project to analyze if my setup of Neo4j was not the problem, by following this tutorial: https://www.sitepoint.com/using-a-graph-database-with-ruby-part-ii-integration/ and the error did not appear. I tried with another with another class in my project and apparently worked well, which leads me to believe that the problem is something specific in User class. Here the parts involved code:

class User < ActiveRecord::Base 
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable

  include Entity
  include Neoid::Node

  extend FriendlyId

  friendly_id :full_name, use: :slugged

  extend Enumerize
  extend ActiveModel::Naming

  neoidable do |c|
    c.field :slug
  end
  [...]
end

class Connection < ActiveRecord::Base

  include Neoid::Relationship

  belongs_to :user
  belongs_to :connected, class_name: User

  neoidable do |c|
    c.relationship start_node: :user, end_node: :connected, type: :connection
  end
end

class CreateConnections < ActiveRecord::Migration
  def change
    create_table :connections do |t|
      t.integer :user_id
      t.integer :connected_id
      t.timestamps
    end
  end
end

The question is, has anyone ever had a problem like this? Or have some feature in the User class that may be causing this error (like Devise, Enumerize ...)?

Already tried: