After 'mix phx.gen.live Items Item items name:string description:string info:string amount:integer factor:float type:string'
This commit is contained in:
26
lib/generic_rest_server/items/item.ex
Normal file
26
lib/generic_rest_server/items/item.ex
Normal file
@ -0,0 +1,26 @@
|
||||
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
|
||||
Reference in New Issue
Block a user