Nested has_many associations with liveview

How I can add/remove a has_many association like this?

RuleGroup ->(has_many) Rules → (has_many) Conditions

This tutorial: Nested model forms with Phoenix LiveView - Tutorials and screencasts for Elixir, Phoenix and LiveView
works well when I dealing with just a associations like this:

RuleGroup ->(has_many) Rules

Sadly, I chose the hardest way to solve, I treat all change/add/remove/validate with my own handle_event, there a way to do this more elegant like in mentioned tutorial?

I do the add, delete and change through their own handle_events. IIRC, I ended up getting the current value from the changeset, adding/removing the item and providing the updated data, as changesets, to put_embed. For the change event, the params arrive in the correct format and are used to create a new changeset against the original data.

My data model is slightly different in that a rule group can contain rules and/or rule groups though.

edit: this slightly adjacent example may be helpful

1 Like