在你的情况下,似乎因为你正在使用@comments.to_sql
您将该准备好的语句拉入您的子选择中,而不为其引入参数。您可以尝试仅包含评论数据,如下所示:
@comments = current_clinician.comments.select('ON (patient_id) *').uniq.order("patient_id, created_at DESC").include(:comment)
@comment_list = @comments.include(:comment)
这个问题似乎也来自 Rails 中准备好的语句的构建方式,并且可能是由 Rails 本身内部的任一问题引起的(Rails 问题)#15920 https://github.com/rails/rails/issues/15920,已在 Rails 4.2 中修复)或通过帮助生成查询的各种 gem 的问题(例如:Rails 问题#20236 https://github.com/rails/rails/issues/20236)或者甚至是你定义模型关联的方式(Rails issues#12852 https://github.com/rails/rails/issues/12852).
可以通过向您的程序添加指令来彻底禁用准备好的语句database.yml
file:
production:
adapter: postgresql
database: prod_dbname
username: prod_user
password: prod_pass
prepared_statements: false
但首先,您可能需要检查并确保没有在模型关联中使用不必要的参数,如下所示:
class DashboardTab < ActiveRecord::Base
has_many :dashboard_tab_feeds, foreign_key: :dashboard_tab_id, dependent: :destroy
has_many :social_feeds, through: :dashboard_tab_feeds
end
class DashboardTabFeed < ActiveRecord::Base
belongs_to :social_feed
belongs_to :dashboard_tab
end
class SocialFeed < ActiveRecord::Base
has_many :dashboard_tab_feeds, foreign_key: :social_feed_id, dependent: :destroy
end
...应该忽略掉foreign_key
, 像这样:
class DashboardTab < ActiveRecord::Base
has_many :dashboard_tab_feeds, dependent: :destroy
has_many :social_feeds, through: :dashboard_tab_feeds
end
class DashboardTabFeed < ActiveRecord::Base
belongs_to :social_feed
belongs_to :dashboard_tab
end
class SocialFeed < ActiveRecord::Base
has_many :dashboard_tab_feeds, dependent: :destroy
end