1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Add opponent association

This commit is contained in:
Daniel Barber 2018-02-18 12:36:36 -05:00
parent 22294bfcda
commit 5ac47f3ac7
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
3 changed files with 11 additions and 0 deletions

View File

@ -11,6 +11,7 @@ defmodule Chess.Auth.User do
field :username, :string
has_many :games, Chess.Store.Game
has_many :other_games, Chess.Store.Game, foreign_key: :opponent_id
timestamps()
end

View File

@ -13,6 +13,7 @@ defmodule Chess.Store.Game do
field :board, :map
belongs_to :user, Chess.Auth.User
belongs_to :opponent, Chess.Auth.User, references: :id
timestamps()
end

View File

@ -0,0 +1,9 @@
defmodule Chess.Repo.Migrations.AddOpponentToGame do
use Ecto.Migration
def change do
alter table("games") do
add :opponent_id, references(:users)
end
end
end