2016-03-26 28 views
0

我試圖編寫Ecto查詢,它將同時從兩個表中選擇數據。像Select t1.*,t2.* from table1 t1,table2 t2 where t1.id=1 and t2.id=2我找不到解決方案,只能找到寫入原始SQL的方法,看起來不太好。如何從Ecto中的兩個表中選擇數據

像變體一樣,使用預加載,但它產生了額外的查詢。

comments_query = from c in Comment, order_by: c.published_at 
Repo.all from p in Post, preload: [comments: ^comments_query] 

感謝您的任何想法

+0

你可以使用一個加入? – JustMichael

回答