如何在Rails 5.2中调用工会而不委托Arel

the*_*zer 5 ruby-on-rails-5

在Rails 5.0中,我可以编写查询

class DC < ApplicationRecord
  has_many :b_elements, through: :c_node
  has_many :d_elements, through: :e_node

  def both
    union = b_elements.union(d_elements)
    elements = Element.arel_table
    Element.from(elements.create_table_alias(union, :elements))
  end
end
Run Code Online (Sandbox Code Playgroud)

当我升级到Rails 5.2时,我会得到弃用错误:

弃用警告:不建议将联合委托给arel,并将在Rails 6.0中将其删除。(从两者处调用。)弃用警告:不推荐将ast委托给arel,并将在Rails 6.0中删除。(从...处调用)

在Rails 5.2中调用联合/相交的正确方法是什么

Mik*_*kov 0

我遇到了同样的问题,发现现在唯一的方法是以最明确的方式编写所有内容。这是例子

c=Company.arel_table
request = c.project('*').where(c[:name].eq 'foo').union(
          c.project('*').where(c[:name].eq 'bar'))
ActiveRecord::Base.connection.select_all request.to_sql
Run Code Online (Sandbox Code Playgroud)