开发者

ROR heroku PostGres issue

getting error:

ActiveRecord::StatementInvalid (PGError: ERROR:  argument of HAVING must be type boolean, not type timestamp without time zone

controller code snippet:

 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
开发者_开发百科

changed

:having => 'MAX(appointments.start_time)'

to

:having => ['MAX(appointments.start_time) <= ?', @number_days.days.ago]

and now error is:

ActiveRecord::StatementInvalid (PGError: ERROR: column "clients.id" must appear in the GROUP BY clause or be used in an aggregate function


The :having clause requires a SQL snippet that evaluates to a boolean. MAX(appointments.start_time) evaluates to a timestamp


change :group => 'client_id' to :group => 'table_name.client_id'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜