68. require 'neo4j'
class Person
include Neo4j::NodeMixin
property :name, :mutant
index :name, :mutant
has_n :crushes
has_n :hookups
has_n :marriages
def initialize(name, mutant = true)
name = name
mutant = mutant
end
end
69. Neo4j::Transaction.run do
magneto = Person.new('Magneto')
esme = Person.new('Esme')
rogue = Person.new('Rogue')
magda = Person.new('Magda', false)
wasp = Person.new('Wasp', false)
magneto.crushes << wasp
magneto.hookups << rogue
magneto.marriages << magda
esme.crushes << magneto
rogue.hookups << magneto
magda.marriages << magneto
end
70. magneto = Person.find(:name => 'Magneto')
# Who likes Magneto?
magneto.relationships.incoming(:crushes).nodes
# Which non-mutants has Magneto dated?
magneto.hookups{ !mutant? }.to_a