2021-06-28 16:32:25 +02:00
|
|
|
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
|
2021-06-28 16:32:25 +02:00
|
|
|
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
|
2021-06-28 16:32:25 +02:00
|
|
|
|
|
|
|
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)/)
|
2021-06-28 16:32:25 +02:00
|
|
|
end
|
|
|
|
end
|