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
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









