아래는 lo가 titres에 속하고 titre가 lo를 많이 가지고 있습니다.connection.select_all 대 레일에 결합으로 선택 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;")
그것을 검색 않습니다.
내가 여기에 실종 됐다는 것에 대해 뭔가 근본적인 것이 있습니까?
또는 선택에서 필드의 검색은 from 데이터베이스 테이블에서 이루어지며 join 테이블에서는 검색되지 않습니다.
이 쿼리를 사용하여 connection.select_all 버전과 동일한 결과를 얻을 수있는 더 좋은 방법이 있습니까?
환경 : 레일 3.0.5 with jruby 1.6 (루비 1.8.7).
미리 알려 주셔서 감사합니다.