下面,lo屬於titres,titre有很多個lo。connection.select_all vs select with with rails in rails 3
當我使用:
LO.select(["los.id","date_ord","soc","pv"]).joins(:titre).
where(['year(date_ord) = ? and pv is not null',"#{date_ord}"]).
group("num_ordre").order("soc,date_ord")
它不檢索滴度領域SOC。
而如果我使用:
search_year = "year(date_ord) = '#{date_ord}'"
connection.select_all("select los.id, date_ord, soc, pv " +
"from los inner join titres on los.titre_id=titres.id " +
"where #{search_year} and pv is not null " +
"group by num_ordre order by soc, date_ord;")
它檢索。
有什麼fondamental我在這裏失蹤?
還是選擇限制從數據庫表中檢索字段,還是從連接表中沒有任何內容?
是否有一個更好的方式來執行此查詢,以便它提供與connection.select_all版本相同的結果?
環境:軌道3.0.5與jruby 1.6(紅寶石1.8.7)。
在此先感謝您的任何提示。