Hello there. I have two schemas, which have an M:M relation
schema “users_details” do
…
fields
…
many_to_many :interests, Project.Accounts.Interests, join_through: “users_details_interests”
schema “interests” do
field :tag, :string
many_to_many :users_details, Project.Accounts.UserDetails, join_through: “users_details_interests”
timestamps()
end
And I have join table, which i create in migration:
create table(:users_details_interests) do add :user_details_id, :bigint add :interests_id, :bigint timestamps() end
How I can input data for interests table in phoenix template?
I tried doing it the way I did for the 1:1 relationship, no errors, but no new fields appeared in the template.
<%= form_for @details_changeset, “#”,
[phx_change: :details_validate, phx_submit: :details_save, phx_hook: “SavedForm”], fn f-> %>
<%= inputs_for f, :interests, fn f2 → %>
<%= label f2, :tag %>
<%= text_input f2, :tag, phx_debounce: “blur” %>
<%= error_tag f2, :tag %>
<% end %><%= submit "Save", phx_disable_with: "Saving..." %><% end %>
However, inputs_for sees the interests table, because if i change “:interests” to something else (e.g. “:test”) in “inputs_for”, i get an error
<%= inputs_for f, :test, fn f2 → %>
<%= label f2, :tag %>
<%= text_input f2, :tag, phx_debounce: “blur” %>
<%= error_tag f2, :tag %>
<% end %>
could not generate inputs for :test from Project.Accounts.UserDetails. Check the field exists and it is one of embeds_one, embeds_many, has_one, has_many, belongs_to or many_to_many