Ash FrameworkAF
Ash Framework3y ago
4 replies
moxley

Does attribute `default: _` not set the struct's default value?

It appears that when defining an attribute's default: value, it doesn't set the default on the generated struct definition. I would expect it would, like
Ecto.Schema
does. Is there a reason it doesn't? Or is there a way of accomplishing this that I couldn't find in the documentation?

defmodule GF.Ash.WebComponent do
  use Ash.Resource,
    data_layer: AshPostgres.DataLayer,
    extensions: [AshGraphql.Resource]

  alias GF.Ash.EmbeddedWebComponent

  attributes do
    attribute :attrs, {:array, EmbeddedWebComponent}, default: []
    attribute :usage, :atom,
      constraints: [one_of: [:attribute, :replacement]],
      default: :attribute
  end
end


component = %WebComponent{}
dbg(component.attrs) # nil
dbg(component.usage) # nil
Was this page helpful?