From a742c8faf0f1bc6400ec001aa23d3acb77c26d6f Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Fri, 23 Feb 2018 11:44:33 -0500 Subject: [PATCH] Add foreign key constraints to game MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not that they seem to be working 🤔 --- lib/chess/store/game.ex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/chess/store/game.ex b/lib/chess/store/game.ex index 12bbf01..33c58e5 100644 --- a/lib/chess/store/game.ex +++ b/lib/chess/store/game.ex @@ -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