-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transition to mainline .inputs_for
code
#466
base: master
Are you sure you want to change the base?
Conversation
https://hexdocs.pm/phoenix_live_view/1.0.0-rc.7/Phoenix.Component.html#inputs_for/1 * makes a lot of code unnecessary * same time, the tests don't seem to be working any more, which isn't great and I have no idea how to really resolve
The tests will fail like this:
I haven't found a satisfactory way to work around this and will work in the forums. Changing it to emit a custom event feels wrong when the docs say to do this. The right move would probably be to emit |
Right using the
|
Created a thread on the elixir forum asking for help: https://elixirforum.com/t/tests-with-render-click-phx-click-js-dispatch-change-fail-best-way-to-fix-testing-inputs-for/67387 |
The one where we delete a label which we shouldn't have creates some problems. Will take a look later at displaying the proper errors and giving it the proper constaint.
Basically works but one of the test cases now needs some work and maybe even some feature work as that's the one about removing labels of associated ideas not working.
|
I knew I hated nested inputs for. I'm not quite sure but currently it explodes saying it has no constraints defined - but we do have constraints! Or well, I fixed that. I'm not 100% sure what ecto does, but it feels like it creates a new changeset which loses the constraints to delete them which robably has some reason. I'm deep debugging into ecto but I need a break now.
|
Alright, I debugged it through and there doesn't seem to be a way around this (currently). Why is this failing?To the best of my understanding as the record is supposed to be deleted (via drop_params) the In the following code our changeset is referred to as on_cast = Keyword.get_lazy(opts, :with, fn -> on_cast_default(type, related) end)
sort = opts_key_from_params(:sort_param, opts, params)
drop = opts_key_from_params(:drop_param, opts, params)
changeset =
if is_map_key(params, param_key) or is_list(sort) or is_list(drop) do
value = Map.get(params, param_key)
original = Map.get(data, key)
current = Relation.load!(data, original)
value = cast_params(relation, value, sort, drop)
case Relation.cast(relation, data, value, current, on_cast) do However, def cast(%{related: mod} = relation, owner, params, current, on_cast) do
pks = mod.__schema__(:primary_key)
fun = &do_cast(relation, owner, &1, &2, &3, &4, on_cast)
But in the cast of removing the element (via defp do_cast(relation, _owner, nil = _params, current, _allowed_actions, _idx, _on_cast) do
on_replace(relation, current)
end This means we end up with a changeset that has no foreign keys defined and hence the AssessmentI still think There are woarkounds, but I don't think they're worth it. So, I think that for now sticking to the existing solution is better (we could tidy it up). I'd wait what I hear from the ecto team before we move forward - generally the team is awesome and responds to issues quickly. Workarounds
|
email on the mailing list: https://groups.google.com/g/elixir-ecto/c/r9BZq13U39E |
Update: it's acknowledged as something ecto can improve and should be an easy fix. |
Back link go #362 for visibility. |
https://hexdocs.pm/phoenix_live_view/1.0.0-rc.7/Phoenix.Component.html#inputs_for/1
Gif showcasing the feature working
(sorry about the editor bleeding in, see it as a feature)
Notes: