2

I have the following model:

class User
  include Neo4j::ActiveNode
end

and I simply want to specify the primary key at creation time:

user = User.create(id: SecureRandom.uuid)

However, this does not work and return Undefined properties: id. I have tried with a custom id_property definition:

class User
  include Neo4j::ActiveNode
  id_property :user_id
end

While this works, it won't provide a default id when doing User.create. So I tried:

class User
  include Neo4j::ActiveNode
  id_property :user_id, auto: :uuid
end

which will assign a default uuid but does not allow User.create(user_id: xxx) anymore!

This is driving me crazy! Am I missing something here?

Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
Pierre-Louis Gottfrois
  • 17,561
  • 8
  • 47
  • 71
  • Using [GraphAware Neo4j UUID](https://github.com/graphaware/neo4j-uuid) is not an option? – Bruno Peres Oct 26 '17 at 16:05
  • Hey Bruno ;) Not sure how that would help, it's for java no? – Pierre-Louis Gottfrois Oct 26 '17 at 16:20
  • Hi Pierre! No. It is a plugin for the Neo4j database. In fact you can use GraphAware UUID in "embedded mode / Java Development". But the [server mode option](https://github.com/graphaware/neo4j-uuid#server-mode) can help you. – Bruno Peres Oct 26 '17 at 16:25
  • In this mode you will download the jar files of GraphAware Neo4j Framework and GraphAware Neo4j UUID .jar. Then paste this jar files into the /plugins directory and edit some lines in the neo4j.conf file, as described [here](https://github.com/graphaware/neo4j-uuid#server-mode-1). – Bruno Peres Oct 26 '17 at 16:27
  • After this process the Neo4j database will create and assign UUIDs for your nodes and relationships automatically. – Bruno Peres Oct 26 '17 at 16:27

1 Answers1

1

This is a long-standing issue with the gem, that you can't set your own IDs on nodes.

Is the SecureRandom.uuid just an example? Because that's exactly what's used for the :uuid strategy (which is the default for the id property). I'm not sure what you're trying to achieve.

The GraphAware UUID plugin is great, though I don't know how it will work with the gem which wants to generate it's own IDs. You might be able to create your own UUID generator which just generates nil values and the let the plugin set the ID (at which point the gem doesn't care about the value, so long as it's present and unique). Unfortunately the gem can't depend on that plugin being installed in all Neo4j servers it's used on.

Hopefully someday in the near future Neo4j will support IDs which don't get recycled so that the gem doesn't need to have it's own UUID logic

Brian Underwood
  • 10,746
  • 1
  • 22
  • 34