forked from shibao/cannery
		
	use belongs_to instead of field for references
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| defmodule Cannery.Ammo.AmmoGroup do | ||||
|   use Ecto.Schema | ||||
|   import Ecto.Changeset | ||||
|   alias Cannery.{Accounts, Ammo, Containers, Tags} | ||||
|  | ||||
|   @primary_key {:id, :binary_id, autogenerate: true} | ||||
|   @foreign_key_type :binary_id | ||||
| @@ -8,10 +9,11 @@ defmodule Cannery.Ammo.AmmoGroup do | ||||
|     field :count, :integer | ||||
|     field :notes, :string | ||||
|     field :price_paid, :float | ||||
|     field :tag_id, :binary_id | ||||
|     field :ammo_type_id, :binary_id | ||||
|     field :container_id, :binary_id | ||||
|     field :user_id, :binary_id | ||||
|  | ||||
|     belongs_to :tag, Tags.Tag | ||||
|     belongs_to :ammo_type, Ammo.AmmoType | ||||
|     belongs_to :container, Containers.Container | ||||
|     belongs_to :user, Accounts.User | ||||
|  | ||||
|     timestamps() | ||||
|   end | ||||
| @@ -19,7 +21,15 @@ defmodule Cannery.Ammo.AmmoGroup do | ||||
|   @doc false | ||||
|   def changeset(ammo_group, attrs) do | ||||
|     ammo_group | ||||
|     |> cast(attrs, [:count, :price_paid, :notes]) | ||||
|     |> validate_required([:count, :price_paid, :notes]) | ||||
|     |> cast(attrs, [:count, :price_paid, :notes, :tag_id, :ammo_type_id, :container_id, :user_id]) | ||||
|     |> validate_required([ | ||||
|       :count, | ||||
|       :price_paid, | ||||
|       :notes, | ||||
|       :tag_id, | ||||
|       :ammo_type_id, | ||||
|       :container_id, | ||||
|       :user_id | ||||
|     ]) | ||||
|   end | ||||
| end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user