如何执行与 Ecto 等效的 ActiveRecord 查询 current_user.articles?

How to perform ActiveRecord's query current_user.articles equivalent with Ecto?

在 Rails 中,AR 可以 运行 这样的查询:

current_user.articles # fetch all articles from current_user
SELECT * from articles where user_id = <user_id>;

Ecto 有等效的方法吗?

articles = Repo.all(from a in assoc(current_user, :articles))

或将文章预加载到用户中

current_user = Repo.preload(current_user, [:articles])
current_user.articles