【发布时间】:2018-04-17 21:14:36
【问题描述】:
我将我的 rails 5.1.4 应用更新为 5.2.0。我的一个模型中有以下范围:
scope :by_category, lambda { |category_slug|
category_ids = Category.find_by(slug: category_slug)&.subtree_ids
where(category_id: category_ids)
}
由于该范围,Rails 向我返回以下错误:
DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "coalesce(\"categories\".\"ancestry\", '')". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql()
我该如何解决这个问题?
【问题讨论】:
-
subtree_ids是什么意思? -
这是来自祖先 gem 的方法:github.com/stefankroes/ancestry
标签: ruby-on-rails ruby ruby-on-rails-5.2