Last active
August 29, 2015 14:22
-
-
Save subvertallchris/ce2b9a7415865a166467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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