5avage
5avage
AEAsh Elixir
Created by 5avage on 7/7/2023 in #support
action argument default to another argument?
Trying to use the value passed in one argument as a default value for a second argument. Is there a way? Something like:
create :new_record do
primary? true
argument :short_name, :string, allow_nil?: false
argument :long_name, :string, default: arg(:short_name)
change set_attribute(:short_name, arg(:short_name))
change set_attribute(:long_name, arg(:long_name))
end
create :new_record do
primary? true
argument :short_name, :string, allow_nil?: false
argument :long_name, :string, default: arg(:short_name)
change set_attribute(:short_name, arg(:short_name))
change set_attribute(:long_name, arg(:long_name))
end
I've tried a few variations on the above and keep getting InvalidArgument compilation errors from Ash.
5 replies
AEAsh Elixir
Created by 5avage on 5/14/2023 in #support
Using ex_money_sql with Ash
I'm hoping to use the Money type defined in the ex_money library as an attribute in Ash resources. This library has a companion, ex_money_sql that creates a Postgres migration and creates a custom type:
def up do
execute("CREATE TYPE public.money_with_currency AS (currency_code varchar, amount numeric);")
end
def up do
execute("CREATE TYPE public.money_with_currency AS (currency_code varchar, amount numeric);")
end
In the documentation, there's a Money struct, a :money_with_currency, a Money.Ecto.Composite.Type all used in various places. I'm very new to Elixir, Ash, and Ecto so it's all a bit confusing. I'm assuming I need a Custom Ash Type (right?), but not sure which identifiers mean what - for example, the existing examples for an Ash custom type all use an atom like :map or :string for storage_type, but it isn't clear to me how they get defined, and if Ash would be able to see custom types in Postgres. Should I bypass the _sql library and roll my own :map-based solution?
7 replies