forked from shibao/cannery
add has_many relationships
This commit is contained in:
parent
ad3f48ccc9
commit
844c8ccdae
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user