如何在 Phoenix/Elixir 中同时插入一个父模型和几个子模型?

How to insert a parent model and a few child ones at once in Phoenix/Elixir?

我有 ArticleCommentary 型号。我想一次插入 and Article 和几个 Commentary。我怎样才能做到这一点?在文档中它没有显示。在 Rails 我会这样做:

article = Article.create!(title: "title1", body: "body1")
article.commentaries = [
    Commentary.create!(body: "comment body1"),
    Commentary.create!(body: "comment body2"),
    Commentary.create!(body: "comment body3")
]
article.save!

Phoenix/Elixir怎么样?

%Article{}
|> Ecto.Changeset.change(title: "title1")
|> Ecto.Changeset.put_assoc(comments: [%Comment{body: "one"}, %Comment{body: "two"}])
|> Repo.insert!()

我相信是这样的,从这里你就会明白了。