Phoenix Framework:inputs_for 是否可用于 has_many 协会?

Phoenix Framework: Is inputs_for available for the has_many associations?

使用Phoenix Framework,我想实现像RoR的fields_for这样的嵌套形式。 今天尝试用inputs_for实现,但是报错

参考Phoenix Framework的官方文档,找到了inputs_for的示例。它仅描述了具有 embed_one 关联的样本。我遇到了 has_many 关联的错误。

如何正确实现 has_many 关联的嵌套形式?

图式如下:

defmodule AnApp.User do
    use PhoenixBlog.Web, :model

    schema "users" do
        field :handle, :string
        field :password_digest, :string

        has_many  :emails
    end
end

defmodule AnApp.Email do
    use PhoenixBlog.Web, :model

    schema "emails" do
        field :address, :string
    end
end

我实现了 form.html.eex 如下:

<%= form_for @changeset, @action, fn f -> %>
    <%= inputs_for f, :emails, fn ef -> %>
    <% end %>
<% end %>

这会导致错误 参数错误:未知字段 :emails

不,目前它只支持嵌入。接下来我们正在努力支持协会。新发布的Phoenix.Ecto中的错误信息应该也更清楚了。