ROR heroku PostGres问题

时间:2010-04-24 04:04:55

标签: ruby-on-rails ruby postgresql heroku

收到错误:

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

2 个答案:

答案 0 :(得分:4)

:having子句需要一个评估为布尔值的SQL片段。 MAX(appointments.start_time)评估时间戳

答案 1 :(得分:0)

更改:group =&gt; 'client_id'到:group =&gt; 'table_name.client_id'