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

24 lines
738 B
Elixir

defmodule PokemonCouture.Shops.Clothes do
use Ecto.Schema
import Ecto.Changeset
schema "clothes" do
field :name, :string
field :color, :string
field :type, :string # shirt, pants, socks, shoes, bag, hat, glasses, accessory
field :game, :string
field :location, :string
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
|> cast(attrs, [:name, :location, :type, :game, :color])
|> validate_required([:name, :location, :type, :game, :color])
|> validate_format(:type, ~r/(shirt)|(pants)|(socks)|(shoes)|(bag)|(hat)|(glasses)|(accessory)/)
end
end