我需要从Post
模式中选择具有10多个字段的特定字段。我还需要选择预加载的:comments
。我该怎么办?
query = from p in Post, preload: [:comments], select: map(p, [:comments, :title])
Repo.all(query)
有多种方法可以执行此操作,具体取决于您希望接收哪种数据结构作为输出。如果要只包含%Post{}
和comments
字段的title
结构,请使用以下查询:
query = from p in Post, preload: [:comments], select: [p.comments, p.title]
Repo.all(query)
否则,请参考文档以获取select查询表达式:-)