ActiveRecord::StatementInvalid (PGError: ERROR: argument of HAVING must be type boolean, not type timestamp without time zone
控制器代碼片段:
def inactive
@number_days = params[:days].to_i || 90
@clients = Client.find(:all,
:include => :appointments,
:conditions => ["clients.user_id = ? AND appointments.start_time <= ?", current_user.id, @number_days.days.ago],
:group => 'client_id',
:having => 'MAX(appointments.start_time)'
)
end
改變
:having => 'MAX(appointments.start_time)'
到
:having => ['MAX(appointments.start_time) <= ?', @number_days.days.ago]
現在的錯誤是:
ActiveRecord::StatementInvalid (PGError: ERROR: column "clients.id" must appear in the GROUP BY clause or be used in an aggregate function
我建議你刷上SQL的WHERE,HAVING和GROUP BY子句。 http://www.w3schools.com/sql/sql_having.asp。這不是一個Rails問題。 – JRL 2010-04-24 15:39:00
是啊,它肯定是一個postgres更嚴格,然後sqlite的東西,只是試圖找到一個解決方案....仍然學習 – sysconfig 2010-04-24 22:31:25