From 844c8ccdae529518320ae357a88737377fe301f0 Mon Sep 17 00:00:00 2001 From: shibao Date: Sat, 5 Feb 2022 01:59:09 -0500 Subject: [PATCH] add has_many relationships --- lib/cannery/ammo/ammo_type.ex | 5 ++++- lib/cannery/containers/container.ex | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/cannery/ammo/ammo_type.ex b/lib/cannery/ammo/ammo_type.ex index 4cc007ad..4465cba4 100644 --- a/lib/cannery/ammo/ammo_type.ex +++ b/lib/cannery/ammo/ammo_type.ex @@ -7,7 +7,7 @@ defmodule Cannery.Ammo.AmmoType do use Ecto.Schema import Ecto.Changeset - alias Cannery.Ammo.AmmoType + alias Cannery.Ammo.{AmmoGroup, AmmoType} alias Ecto.{Changeset, UUID} @primary_key {:id, :binary_id, autogenerate: true} @@ -20,6 +20,8 @@ defmodule Cannery.Ammo.AmmoType do field :name, :string field :grain, :integer + has_many :ammo_groups, AmmoGroup + timestamps() end @@ -31,6 +33,7 @@ defmodule Cannery.Ammo.AmmoType do manufacturer: String.t(), name: String.t(), grain: integer(), + ammo_groups: [AmmoGroup.t()] | nil, inserted_at: NaiveDateTime.t(), updated_at: NaiveDateTime.t() } diff --git a/lib/cannery/containers/container.ex b/lib/cannery/containers/container.ex index 15339dc1..d48c5114 100644 --- a/lib/cannery/containers/container.ex +++ b/lib/cannery/containers/container.ex @@ -6,7 +6,7 @@ defmodule Cannery.Containers.Container do use Ecto.Schema import Ecto.Changeset alias Ecto.{Changeset, UUID} - alias Cannery.{Accounts.User, Containers.Container} + alias Cannery.{Accounts.User, Ammo.AmmoGroup, Containers.Container} @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id @@ -18,6 +18,8 @@ defmodule Cannery.Containers.Container do belongs_to :user, User + has_many :ammo_groups, AmmoGroup + timestamps() end @@ -29,6 +31,7 @@ defmodule Cannery.Containers.Container do type: String.t(), user: User.t(), user_id: User.id(), + ammo_groups: [AmmoGroup.t()] | nil, inserted_at: NaiveDateTime.t(), updated_at: NaiveDateTime.t() }