【发布时间】:2012-11-24 04:54:13
【问题描述】:
我遇到了类似的错误
Mysql2::Error: Unknown column 'ctr' in 'having clause': SELECT COUNT(*) AS count_all, artists.id AS artists_id FROM `artists` INNER JOIN `photos` ON `photos`.`photoable_id` = `artists`.`id` AND `photos`.`photoable_type` = 'Artist' WHERE (admin_approved = 1) GROUP BY artists.id HAVING ctr >= 2
我的艺术家模型我写范围
scope :approved, where("admin_approved = ?", true)
scope :completed_profile, joins(:photos).select("artists.*,count(photos.id) as ctr").group("artists.id").having("ctr >= 2")
在我的控制器中我写
def artists_completed_profile
@artists = Artist.approved.completed_profile.page(params[:page]).per(10)
@total_artists = @artists.size
end
注意:当我在控制台中尝试时,我没有收到任何错误,但是当我在模型或控制器中写入时,我会收到此错误。
提前致谢
【问题讨论】:
-
你的服务器运行在什么模式下?
-
再次运行迁移。如果失败,请重新启动您的网络服务器。
标签: mysql ruby-on-rails ruby-on-rails-3.2 rails-activerecord