Skip to content

Instantly share code, notes, and snippets.

@subvertallchris
Last active August 29, 2015 14:22
Show Gist options
  • Save subvertallchris/ce2b9a7415865a166467 to your computer and use it in GitHub Desktop.
Save subvertallchris/ce2b9a7415865a166467 to your computer and use it in GitHub Desktop.
class Team
include Neo4j::ActiveNode
property :name, type: String
has_one :out, :league, type: :PLAY_IN
end
class League
include Neo4j::ActiveNode
property :name, type: String
property :rank, type: Integer
has_many :in, :teams, origin: :league
end
team = Team.create(name: 'Springfield Isotopes')
league = League.create(name: 'The Minor League')
team.league = league
# Same as:
# league.teams << team
# returns our league
team.league
# returns our team using the same relationship but from the other side
league.teams.first
# returns an AssociationProxy object, not executed until you call `to_a`, `first`, etc,...
match = league.teams.where(name: 'Springfield Isotopes')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment