Nan*_*usa 4 elixir ecto phoenix-framework
在Rails AR中可以运行如下查询:
current_user.articles # fetch all articles from current_user
SELECT * from articles where user_id = <user_id>;
Run Code Online (Sandbox Code Playgroud)
有一种与Ecto相同的方法吗?
articles = Repo.all(from a in assoc(current_user, :articles))
Run Code Online (Sandbox Code Playgroud)
或者将文章预加载到用户中
current_user = Repo.preload(current_user, [:articles])
current_user.articles
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
151 次 |
| 最近记录: |