fummmp
fummmp
AEAsh Elixir
Created by fummmp on 1/28/2023 in #support
Create Resource without relation
@Zach Daniel you're my hero! It works! Thank you again for the more than quick response and the effort to fix the bug immediately!
34 replies
AEAsh Elixir
Created by fummmp on 1/28/2023 in #support
Create Resource without relation
Will try tomorrow! Now I need some sleep..it’s 3AM here in Germany πŸ™ˆ
34 replies
AEAsh Elixir
Created by fummmp on 1/28/2023 in #support
Create Resource without relation
Oh wow! You absolutely made my day now! ❀️
34 replies
AEAsh Elixir
Created by fummmp on 1/28/2023 in #support
Create Resource without relation
I saw part 1 of the video yesterday and it finally made me try Ash. Excited for part 2! πŸŽ‰
34 replies
AEAsh Elixir
Created by fummmp on 1/28/2023 in #support
Create Resource without relation
@Zach Daniel you are amazing!
34 replies
AEAsh Elixir
Created by fummmp on 1/28/2023 in #support
Create Resource without relation
Thank you for the quick reply! It's mostly complete but here's the full module
defmodule Inventizr.Inventory.Item do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAdmin.Resource]

postgres do
table "items"
repo Inventizr.Repo
end

actions do
defaults [:create, :read, :update, :destroy]

read :list do
description "lists all the items"
prepare build(sort: [inserted_at: :desc])
end

create :new do
accept [:model, :brand]
end
end

attributes do
uuid_primary_key :id

attribute :brand, :string
attribute :model, :string

attribute :status, :atom do
constraints one_of: [:available, :in_use, :defect, :unavailable]
default :available
allow_nil? false
end
end

relationships do
belongs_to :user, Inventizr.Accounts.User do
api Inventizr.Accounts
attribute_writable? true
allow_nil? true
end
end

code_interface do
define_for Inventizr.Inventory
define :list, action: :read
define :new
end
end
defmodule Inventizr.Inventory.Item do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAdmin.Resource]

postgres do
table "items"
repo Inventizr.Repo
end

actions do
defaults [:create, :read, :update, :destroy]

read :list do
description "lists all the items"
prepare build(sort: [inserted_at: :desc])
end

create :new do
accept [:model, :brand]
end
end

attributes do
uuid_primary_key :id

attribute :brand, :string
attribute :model, :string

attribute :status, :atom do
constraints one_of: [:available, :in_use, :defect, :unavailable]
default :available
allow_nil? false
end
end

relationships do
belongs_to :user, Inventizr.Accounts.User do
api Inventizr.Accounts
attribute_writable? true
allow_nil? true
end
end

code_interface do
define_for Inventizr.Inventory
define :list, action: :read
define :new
end
end
34 replies
AEAsh Elixir
Created by fummmp on 1/28/2023 in #support
Create Resource without relation
Sure
** (UndefinedFunctionError) function Ash.NotLoaded.__changeset__/0 is undefined or private
(ash 2.5.10) Ash.NotLoaded.__changeset__()
(ecto 3.9.4) lib/ecto/changeset.ex:409: Ecto.Changeset.change/2
(ecto 3.9.4) lib/ecto/changeset/relation.ex:173: Ecto.Changeset.Relation.do_change/4
(ecto 3.9.4) lib/ecto/changeset/relation.ex:335: Ecto.Changeset.Relation.single_change/5
(ecto 3.9.4) lib/ecto/changeset/relation.ex:165: Ecto.Changeset.Relation.change/3
(ecto 3.9.4) lib/ecto/changeset/relation.ex:542: anonymous fn/4 in Ecto.Changeset.Relation.surface_changes/3
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto 3.9.4) lib/ecto/changeset/relation.ex:529: Ecto.Changeset.Relation.surface_changes/3
(ecto 3.9.4) lib/ecto/repo/schema.ex:336: Ecto.Repo.Schema.do_insert/4
(ash_postgres 1.3.3) lib/data_layer.ex:1018: AshPostgres.DataLayer.create/2
(ash 2.5.10) lib/ash/actions/create.ex:415: anonymous fn/8 in Ash.Actions.Create.as_requests/5
(ash 2.5.10) lib/ash/changeset/changeset.ex:1588: Ash.Changeset.run_around_actions/2
(ash 2.5.10) lib/ash/actions/create.ex:317: anonymous fn/9 in Ash.Actions.Create.as_requests/5
(ash 2.5.10) lib/ash/engine/request.ex:1028: Ash.Engine.Request.do_try_resolve_local/4
(ash 2.5.10) lib/ash/engine/request.ex:282: Ash.Engine.Request.do_next/1
(ash 2.5.10) lib/ash/engine/request.ex:211: Ash.Engine.Request.next/1
(ash 2.5.10) lib/ash/engine/engine.ex:650: Ash.Engine.advance_request/2
(ash 2.5.10) lib/ash/engine/engine.ex:556: Ash.Engine.fully_advance_request/2
(ash 2.5.10) lib/ash/engine/engine.ex:497: Ash.Engine.do_run_iteration/2
iex:5: (file)
** (UndefinedFunctionError) function Ash.NotLoaded.__changeset__/0 is undefined or private
(ash 2.5.10) Ash.NotLoaded.__changeset__()
(ecto 3.9.4) lib/ecto/changeset.ex:409: Ecto.Changeset.change/2
(ecto 3.9.4) lib/ecto/changeset/relation.ex:173: Ecto.Changeset.Relation.do_change/4
(ecto 3.9.4) lib/ecto/changeset/relation.ex:335: Ecto.Changeset.Relation.single_change/5
(ecto 3.9.4) lib/ecto/changeset/relation.ex:165: Ecto.Changeset.Relation.change/3
(ecto 3.9.4) lib/ecto/changeset/relation.ex:542: anonymous fn/4 in Ecto.Changeset.Relation.surface_changes/3
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto 3.9.4) lib/ecto/changeset/relation.ex:529: Ecto.Changeset.Relation.surface_changes/3
(ecto 3.9.4) lib/ecto/repo/schema.ex:336: Ecto.Repo.Schema.do_insert/4
(ash_postgres 1.3.3) lib/data_layer.ex:1018: AshPostgres.DataLayer.create/2
(ash 2.5.10) lib/ash/actions/create.ex:415: anonymous fn/8 in Ash.Actions.Create.as_requests/5
(ash 2.5.10) lib/ash/changeset/changeset.ex:1588: Ash.Changeset.run_around_actions/2
(ash 2.5.10) lib/ash/actions/create.ex:317: anonymous fn/9 in Ash.Actions.Create.as_requests/5
(ash 2.5.10) lib/ash/engine/request.ex:1028: Ash.Engine.Request.do_try_resolve_local/4
(ash 2.5.10) lib/ash/engine/request.ex:282: Ash.Engine.Request.do_next/1
(ash 2.5.10) lib/ash/engine/request.ex:211: Ash.Engine.Request.next/1
(ash 2.5.10) lib/ash/engine/engine.ex:650: Ash.Engine.advance_request/2
(ash 2.5.10) lib/ash/engine/engine.ex:556: Ash.Engine.fully_advance_request/2
(ash 2.5.10) lib/ash/engine/engine.ex:497: Ash.Engine.do_run_iteration/2
iex:5: (file)
34 replies