mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Add foreign key constraints to game
Not that they seem to be working 🤔
This commit is contained in:
parent
34b985fa77
commit
a742c8faf0
@ -19,12 +19,11 @@ defmodule Chess.Store.Game do
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Builds a changeset based on the `struct` and `params`.
|
||||
"""
|
||||
def create_changeset(struct, params \\ %{}) do
|
||||
struct
|
||||
|> cast(params, required_attrs())
|
||||
|> foreign_key_constraint(:user_id)
|
||||
|> foreign_key_constraint(:opponent_id)
|
||||
|> put_change(:board, Board.default)
|
||||
|> validate_required(required_attrs())
|
||||
end
|
||||
@ -32,6 +31,8 @@ defmodule Chess.Store.Game do
|
||||
def changeset(struct, params \\ %{}) do
|
||||
struct
|
||||
|> cast(params, required_attrs())
|
||||
|> foreign_key_constraint(:user_id)
|
||||
|> foreign_key_constraint(:opponent_id)
|
||||
|> validate_required(required_attrs())
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user