Hey guys, I'm dipping my toes into Ash and try to build a small thing, but now I'm stuck. I created a resource and a relationship. I want to create the resource, but the relationship can be empty. But when I try to create the resource, I get this error:
iex(5)> Inventizr.Inventory.Item |> Ash.Changeset.for_create(:new, %{model: "MacBook", brand: "Apple"}) |> Inventizr.Inventory.create!()[debug] QUERY OK db=2.3ms idle=1636.8msbegin [][debug] QUERY OK db=2.4msrollback []** (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...
iex(5)> Inventizr.Inventory.Item |> Ash.Changeset.for_create(:new, %{model: "MacBook", brand: "Apple"}) |> Inventizr.Inventory.create!()[debug] QUERY OK db=2.3ms idle=1636.8msbegin [][debug] QUERY OK db=2.4msrollback []** (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...
The resource is defined as:
defmodule Inventizr.Inventory.Item do use Ash.Resource, data_layer: AshPostgres.DataLayer 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 allow_nil? true end endend
defmodule Inventizr.Inventory.Item do use Ash.Resource, data_layer: AshPostgres.DataLayer 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 allow_nil? true end endend
And the corresponding relation:
attributes do uuid_primary_key :id attribute :name, :string end relationships do has_many :items, Inventizr.Inventory.Item do api Inventizr.Inventory end endend
attributes do uuid_primary_key :id attribute :name, :string end relationships do has_many :items, Inventizr.Inventory.Item do api Inventizr.Inventory end endend
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.