【发布时间】:2018-02-25 04:10:04
【问题描述】:
我在一个模型中有两个范围。两者都使用joins。 joins 似乎与 Rails 5 或查询不兼容。
例子:
class Blog < ApplicationRecord
has_many :comments
scope :with_comment_likes, -> {joins(:comments).merge(Comment.some_scope_on_comment)}
scope :some_other_comment_merge_scope, -> {joins(:comments).merge(Comment.other_scope)}
scope :aggregate_or_scope, -> {with_comment_likes.or(some_other_comment_merge_scope)}
end
Blog.aggregate_or_scope
返回错误:
ArgumentError: Relation passed to #or must be structurally compatible.
Incompatible values: [:joins]
关于如何解决这个问题的任何建议?我难住了。我确实看到了this question,但我无法应用它。
【问题讨论】:
-
您使用的是什么版本的 Rails?无法在 5.1.4 上重现此错误(可能已经修复)
-
我确信它是 5.1.0 之前的 Rails 版本。
-
这仍然发生在 Rails 6 中。
标签: ruby-on-rails ruby