matt-savvy

matt-savvy

Creating forms with change manage_relationship not loading values

I have a resource TodoTask that has a many-to-many with a Context like so

# in todo_task
    relationships do
      has_many :context_relationships, TodoTaskContext do
        destination_attribute :task_id
      end

      many_to_many :contexts, Context do
        join_relationship :context_relationships
        source_attribute_on_join_resource :task_id
        destination_attribute_on_join_resource :context_id
      end
    end

I’m trying to set up the form and change so that all existing Contexts are listed as checkboxes, and when the form is submitted, there will be a TodoTaskContext created for this TodoTask and Context. I have this working correctly in a unit test with a manage_relationship that looks like this:

  # in todo_task
     update :update do
        accept ...
        argument :contexts, {:array, :string}, allow_nil?: true, default: []
        require_atomic? false

        change manage_relationship(:contexts, :context_relationships,
                 value_is_key: :context_id,
                 type: :direct_control
               )
      end

and I’m creating a form in my LV like so

AshPhoenix.Form.for_update(task, :update, as: "task")

But the related contexts aren’t being loaded. When I log out my @form[:contexts], the value is always an empty list.

%{
  id: "task_contexts",
  name: "task[contexts]",
  value: [],
  __struct__: Phoenix.HTML.FormField,
  field: :contexts,
  errors: []
}

I’ve made sure my relationships are loaded just before creating AshPhoenix.Form.for_update, but that doesn’t seem to change anything:

    task = task |> Ash.load!([:contexts, :context_relationships])

Is there something wrong with how I’ve got my manage_relationship set up? Or is there something else I need to add?

Thanks!

Most Liked

matt-savvy

matt-savvy

Oh snap, just saw that. Happy to help, wasn’t really expecting that to land on main. So I’m assuming the related code change actually just prevents the BadMapError.

Thanks for all the help digging into this issue. At this point, I think I at least have a little better understanding, so I’ll probably tinker with my code and see if there seems to be an easy way to set this up so that we don’t need to manually transform the changeset data to get the values.

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
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
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

We're in Beta

About us Mission Statement