Elixir 在EXTO中预加载嵌套关联

Elixir 在EXTO中预加载嵌套关联,elixir,ecto,Elixir,Ecto,我有4个模型,它们关联为 表格 has_many :form_fields, FormField, on_delete: :delete_all has_many :fields, through: [:form_fields, :field] has_many :conditions, Condition, on_delete: :delete_all 字段 has_many :form_fields, FormField, on_delete: :delete_all has_many :

我有4个模型,它们关联为

表格

has_many :form_fields, FormField, on_delete: :delete_all
has_many :fields, through: [:form_fields, :field]
has_many :conditions, Condition, on_delete: :delete_all
字段

has_many :form_fields, FormField, on_delete: :delete_all
has_many :forms, through: [:form_fields, :form]
has_many :conditions, Condition, on_delete: :delete_all
belongs_to :form, Form
belongs_to :field, Field
FormField

has_many :form_fields, FormField, on_delete: :delete_all
has_many :forms, through: [:form_fields, :form]
has_many :conditions, Condition, on_delete: :delete_all
belongs_to :form, Form
belongs_to :field, Field
条件

belongs_to :field, Field
belongs_to :form, Form
我想编写一个查询,以获取一个表单,该表单的
id
以及每个字段中的
字段
条件
(对于
表单和
字段
)都是已知的

例如:要获取id为1的表单

%{
    id: 1,
    fields: [
        %{
            id: 1,
            conditions: [
                %{
                    id: 1
                    form_id: 1,
                    field_id: 1
                },
                %{
                    id: 2
                    form_id: 1,
                    field_id: 1
                }
            ]
        },
        %{
            id: 2,
            conditions: [
                %{
                    id: 3
                    form_id: 1,
                    field_id: 2
                },
                %{
                    id: 4
                    form_id: 1,
                    field_id: 2
                }
            ]
        }
    ]
}

我的问题被标记为可能的重复,而且非常直截了当。但我的情况与此略有不同。请看一下这两个问题,并帮助我克服这一步

对不起,伙计们。下面的查询成功了

form_conditions =
  Condition
  |> where(form_id: ^id)
form =
  Form
  |> where(id: ^id)
  |> preload(fields: [conditions: ^form_conditions])
  |> Repo.one!

对不起,伙计们。下面的查询成功了

form_conditions =
  Condition
  |> where(form_id: ^id)
form =
  Form
  |> where(id: ^id)
  |> preload(fields: [conditions: ^form_conditions])
  |> Repo.one!

你有没有尝试过文档()中的任何内容?可能是@Dogbert的副本是的,我查看了文档。但是我没能实现我想要的,你有没有从文档中尝试过什么()?可能是@Dogbert的重复是的,我查看了文档。但我无法实现我想要的