Skip to content

Neo4j::Rails Config

andreasronge edited this page Apr 27, 2012 · 17 revisions

Configuration

You can set the location of the database in the config/application.rb file.
Example:

config.neo4j.storage_path = "#{config.root}/db/neo4j-#{Rails.env}"
config.neo4j.timestamps = false  # disable automatic timestamps on updated_at and created_at properties

Deployment

Trinidad needs the Java jar files in the lib folder.
There is a script for doing this:


neo4j-jars -local

Just type neo4j-jars for help

If you forget to add those jar files to your rails project you may get the following error message:


No index provider ‘lucene’ found

Backup

See Configuration & Backup

Add the following line in your config/application.rb file:

config.neo4j.online_backup_enabled = true

Then add the correct jar files to the lib folder:

neo4j-jars -backup

To perform the backup

require 'neo4j'
Neo4j.load_online_backup
Neo4j::OnlineBackup('localhost').incremental('/var/backup')

HA Cluster

Add the following line in your config/application.rb file:

config.neo4j['ha.db']=true

Then add the correct jar files to the lib folder:

cd YOUR_RAILS_ROOT
neo4j-jars -ha

FAQ

I get “No index provider ‘lucene’ found”

See deployment above.

org.neo4j.kernel.impl.core.ReadOnlyDbException

You get this exception if there is already an neo4j db instance running.
Only one write instance of the database is possible. If there is already a write instance running then a read only db will be created.
Did you run the rails console before you did the first request to rails ?

Does neo4j have an Identity Map ?

Yes but it is disabled by default. Read more about it here: the identity map
and Neo4j::IdentityMap

Why can’t I update nested models: node.nested << x; node.nested.save ?

Because you have not enabled identity map, see above.
Let say you have the following class:

class Person < Neo4j::Rails::Model
  has_one(:nested)
end

node = Person.create
node.nested = Person.create
node.save

Then you can’t update the node.nested

node.nested[:some_property] = 'some value'
node.nested.nested << other_node
node.nested.save

Instead you must use a temporary variable, like this:

tmp = node.nested
tmp[:some_property] = 'some value'
tmp.nested << other_node
tmp.save

The reason is that the node.nested creates a new instance of a
wrapped node.

However, the following will work:

n = Person.create
n.nested = Person.create
n.nested[:name] = 'foo'
n.save

n.nested[:name] # => 'foo'

You do not need a temporary variable in this case since the relationship is not
persisted yet.

Clone this wiki locally