2016-09-23 20 views
0

我已經這個嵌套包括結構ActiveRecord的丟失從子句mutlipe那裏的條件

Converter. 
includes(:converter_params, user: [:address]). 
where('converters.is_active=? AND converter_params.date >= ?', true, 3.month.ago) 

這是工作而不 的AND converter_params.date條件。添加此錯誤會得到錯誤

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "converter_params" 

converter_prams存在且名稱正確。 我無法弄清楚爲什麼,很多感謝提前的幫助。

+1

有型號命名MVC應用程序中的「Controller」聽起來像是一場災難。 – max

+0

:D它其實不是控制器,只是想讓它更具通用性,但我同意 – theDrifter

回答

1

好像你應該明確地給出了一個參考:converter_params表:

Converter. 
includes(:converter_params, user: [:address]). 
where('converters.is_active=? AND converter_params.date >= ?', true, 3.month.ago).references(:converter_params) 

「對於SQL片段,你需要使用引用強制連接的表:」作爲陳述here

+0

呵呵!非常感謝!。我想我得買些眼鏡或什麼的,因爲我還記得有關這方面的消息! – theDrifter