Skip to content

Instantly share code, notes, and snippets.

@hayksaakian
Last active December 15, 2015 00:49
Show Gist options
  • Save hayksaakian/5175166 to your computer and use it in GitHub Desktop.
Save hayksaakian/5175166 to your computer and use it in GitHub Desktop.
model relations for a card game
# game.rb
has_many :hands
has_and_belongs_to_many :users
embeds_many :spaces
# hand.rb
belongs_to :user
belongs_to :game
has_many :cards
# user.rb
has_and_belongs_to_many :games
has_many :hands
has_many :cards
# space.rb
embedded_in :game
has_one :card
# card.rb
belongs_to :space
belongs_to :hand
belongs_to :user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment