mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Add opponent association
This commit is contained in:
parent
22294bfcda
commit
5ac47f3ac7
@ -11,6 +11,7 @@ defmodule Chess.Auth.User do
|
|||||||
field :username, :string
|
field :username, :string
|
||||||
|
|
||||||
has_many :games, Chess.Store.Game
|
has_many :games, Chess.Store.Game
|
||||||
|
has_many :other_games, Chess.Store.Game, foreign_key: :opponent_id
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,6 +13,7 @@ defmodule Chess.Store.Game do
|
|||||||
field :board, :map
|
field :board, :map
|
||||||
|
|
||||||
belongs_to :user, Chess.Auth.User
|
belongs_to :user, Chess.Auth.User
|
||||||
|
belongs_to :opponent, Chess.Auth.User, references: :id
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -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
|
||||||
Loading…
Reference in New Issue
Block a user