defmodule GenericRestServer.Items.Item do use Ecto.Schema import Ecto.Changeset @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id schema "items" do field :name, :string field :description, :string field :info, :string field :amount, :integer field :factor, :float field :type, :string field :user_id, :binary_id timestamps(type: :utc_datetime) end @doc false def changeset(item, attrs, user_scope) do item |> cast(attrs, [:name, :description, :info, :amount, :factor, :type]) |> validate_required([:name, :description, :info, :amount, :factor, :type]) |> put_change(:user_id, user_scope.user.id) end end