2010-04-24 69 views
1

收到錯誤:ROR的Heroku Postgres的問題

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

+0

我建議你刷上SQL的WHERE,HAVING和GROUP BY子句。 http://www.w3schools.com/sql/sql_having.asp。這不是一個Rails問題。 – JRL 2010-04-24 15:39:00

+0

是啊,它肯定是一個postgres更嚴格,然後sqlite的東西,只是試圖找到一個解決方案....仍然學習 – sysconfig 2010-04-24 22:31:25

回答

4

:having子句需要一個計算爲布爾值的SQL代碼段。 MAX(appointments.start_time)計算結果爲時間戳

0

變化:組=> 'CLIENT_ID' 到:組=> 'table_name.client_id'