【发布时间】:2018-05-04 18:52:25
【问题描述】:
我正在尝试将 has_many 关联预加载到传入的结构以及传入的结构关联的 has_many 关联。
这是我现在正在使用的:
project =
Repo.get!(Project, id)
|> Repo.preload([rows: {query, [images: from i in Image, order_by: i.index]}])
但这会返回此错误:
This error may happen when you forget a comma in a list or other container:
[a, b c, d]
Elixir cannot compile otherwise. Syntax error before: ','
这很好用:
project =
Repo.get!(Project, id)
|> Repo.preload([rows: {query, [:images]}])
但在此查询中,我无法对图像进行我想要的排序。有人可以帮我解决这个问题吗?
【问题讨论】:
-
[images: from(i in Image, order_by: i.index)]? -
是的,就是这样。谢谢!我认为这种情况下的括号是可选的?我猜不是。
-
它们通常是可选的,但由于我在回答中描述的模棱两可,这里是必需的。
标签: elixir phoenix-framework ecto