mithereal

mithereal

Passing a action value from accept to a change

i guess an example would work best, but im trying to pass currency to a changeset via the acton , can you tell me what im doing wrong

 actions do
    defaults [:read, :destroy]

    create :create do
      primary? true
      accept [
        :status,
        :customer_id,
        :delivery_date,
        :invoice_number,
        :invoice_status,
        :invoiced_at,
        :payment_method,
        :discount_type,
        :discount_value,
        :delivery_method,
        :currency
      ]

      argument :items, {:array, :map}

      change manage_relationship(:items, type: :direct_control)
      change {CalculateTotals, [currency: arg(:currency) ]}
      change {ValidateConstraints, []}
    end

First Post!

zachdaniel

zachdaniel

Creator of Ash

You can’t do it currently with attributes the way that you can with arg. You have two options:

  1. in the change access it via Ash.Changeset.get_attribute
  2. change it to an argument:
actions do
    defaults [:read, :destroy]

    create :create do
      primary? true
      accept [
        :status,
        :customer_id,
        :delivery_date,
        :invoice_number,
        :invoice_status,
        :invoiced_at,
        :payment_method,
        :discount_type,
        :discount_value,
        :delivery_method
      ]

      argument :currency, :string
      argument :items, {:array, :map}

      change set_attribute(:currency, arg(:currency))
      change manage_relationship(:items, type: :direct_control)
      change {CalculateTotals, [currency: arg(:currency) ]}
      change {ValidateConstraints, []}
    end

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement