Skip to content

Instantly share code, notes, and snippets.

@avifoxi
Created August 9, 2014 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avifoxi/c5a2fbdda97ac63e4794 to your computer and use it in GitHub Desktop.
Save avifoxi/c5a2fbdda97ac63e4794 to your computer and use it in GitHub Desktop.
## within Deck MODEL
belongs_to :author, class_name :user
# in the DECK migration - add column
t.references :author
# in USER MODEL
has_many :played_decks, through: :rounds, source: "Deck"
has_many :authored_decks, class_name: "Deck"
## user has relationship to deck in 2 ways
# 1 => as a player
# 2 => as a an author
# => User.played_decks
# => User.authored_decks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment