Hi all,
I’ve been trying to figure this out all day. I’m still really new Phoenix so I’m not exactly sure where to look to try to resolve this issue.
I am working with a form that has a many-to-many relationship. The form has nested inputs. I believe I have set up the relationships properly, and I have also set up the proper changesets. When I try to render the form, I get the following error: no function clause matching in Ecto.Changeset.cast/4
.
Here’s the form which is for a %WebApp.Meetings.Meeting
struct.
<%= form_for @changeset, @action, fn f -> %>
<%= label f, :title %>
<%= text_input f, :title %>
<%= error_tag f, :title %>
<%= label f, :description %>
<%= text_input f, :description %>
<%= error_tag f, :description %>
<%= inputs_for f, :users, fn user_form -> %>
<%= text_input user_form, :id %>
<% end %>
<div>
<%= submit "Save" %>
</div>
<% end %>
The error originates from the <%= inputs_for f
call.
Here’s the stack trace:
Here’s the changeset called by the form:
defmodule WebApp.Meetings.Meeting do
def changeset(meeting, attrs) do
meeting
|> cast(attrs, [:title, :description, :utc_datetime, :timezone])
|> cast_assoc(:users, with: &WebApp.Accounts.User.meetings_changeset/2)
end
end
And here’s the changeset for the association:
defmodule WebApp.Accounts.User do
def meetings_changeset(user, attrs) do
user
|> cast(attrs, [:email, :id])
end
end
Tinkering around the code, I’ve determined that the last cast
seems to be the issue and I don’t really understand why.
Hoping someone can help!