neo4jrb / activegraph

An active model wrapper for the Neo4j Graph Database for Ruby.
http://neo4jrb.io
MIT License
1.4k stars 276 forks source link

Neo4j::Shared::Property::UndefinedPropertyError: Undefined properties: [variable] #1472

Closed softwareeverything closed 6 years ago

softwareeverything commented 6 years ago

I'm trying to create a new user for neo4j; User.create!(uid: 101, name: 'Jane Garden')

But I get an error which is; Neo4j::Shared::Property::UndefinedPropertyError: Undefined properties: uid

models/user.rb;

class User 
  include Neo4j::ActiveNode
  id_property :uid, type: Integer, on: :primary_key
  property :name, type: String
  property :created_at
  property :updated_at

  has_many :out, :tweets, type: :HAS_TWEET

  validates :name, presence: true
end

I'm using twitter api and I used uid for twitter user id.

db/neo4j/migration;

class CreateUser < Neo4j::Migrations::Base
  def up
    add_constraint :User, :uuid
  end

  def down
    drop_constraint :User, :uuid
  end
end

Runtime information:

Runtime information: Neo4j database version: neo4j 3.3.1 neo4j gem version: 9.0.7 neo4j-core gem version: 8.1.0

softwareeverything commented 6 years ago

Now, I made drop uuid constraint at migrations after that added uid constraint but it still throw the same error.

cheerfulstoic commented 6 years ago

Hey @softwareeverything sorry for the delay in responding!

If you make something an id_property (uuid is the default for this, but you've made a uid property which is the id_property), it's not considered one of the attributes and it can't be set by you.

I'd suggest leaving uuid as the default id_property (which means you don't need to specify anything for id_property) and make a regular property called uid. Then you can set a unique constraint on uid (in addition to a unique constraint on uuid). This makes sure that the property is unique but it will also give you an index for querying on the uid property.

Closing because I don't think there's a feature / issue here, but happy to continue the conversation