pokemon-couture/lib/pokemon_couture/shops/clothes.ex

24 lines
752 B
Elixir
Raw Normal View History

defmodule PokemonCouture.Shops.Clothes do
use Ecto.Schema
import Ecto.Changeset
schema "clothes" do
2021-06-30 14:03:08 +02:00
field :name, :string
field :color, :string
2021-09-28 15:37:52 +02:00
field :type, :string # shirt, bottoms, socks, shoes, bag, hat, eyewear, hair accessory
field :game, :string
field :location, :string
2021-09-14 17:24:08 +02:00
many_to_many :users, PokemonCouture.Accounts.User, join_through: "ownerships", unique: :true, on_replace: :delete
timestamps()
end
@doc false
def changeset(clothes, attrs) do
clothes
2021-09-24 14:43:41 +02:00
|> cast(attrs, [:name, :location, :type, :game, :color])
|> validate_required([:name, :location, :type, :game, :color])
2021-09-28 15:37:52 +02:00
|> validate_format(:type, ~r/(shirt)|(bottoms)|(socks)|(shoes)|(bag)|(hat)|(eyewear)|(hair accessory)/)
end
end