mrsnow

mrsnow

Action change not running

Hey. Maybe i’m missing something. I have a create action with some global changes but the changes are not running.

actions do
    defaults [:update, :destroy]

    read :read do
      primary? true
    end

    read :list do
      filter expr(owner == ^actor(:id))
    end

    create :create do
      accept [:subject]

      change relate_actor(:owner, allow_nil?: true)
    end

    update :update_todo do
      accept [:subject]
      require_atomic? false
    end
  end

  preparations do
    prepare build(sort: [due_at: :asc, hashes: :asc, title: :asc])
  end

  changes do
    change {Elephouse.TodoList.Changes.Title, attribute: :title}
    change {Elephouse.TodoList.Changes.Hashtags, attribute: :hashes}
    change {Elephouse.TodoList.Changes.DueDate, attribute: :due_at}
  end

If i change accept [:subject] to an argument the changes run just fine.
So i’m missing something or are changes only run with arguments?

EDIT:
Changing it to this it works:

create :create do
      argument :subject, :string
      allow_nil_input [:subject]

      change set_attribute(:subject, arg(:subject))
      change relate_actor(:owner, allow_nil?: true)
    end

Marked As Solved

mrsnow

mrsnow

Found the solution for this one.
In the custom Changes i used Ash.Changeset.get_argument which doesn’t get anything when the action only uses attributes.
So changing that to Ash.Changeset.get_argument_or_attribute got them more flexible and they worked again.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
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 42716 114
New

We're in Beta

About us Mission Statement