我正在用Rails应用程序重写一些查询以使用ROM。最初,我在数组中添加了一些选择列,如下所示:
offers = Offer.arel_table
l1_select << offers[:finance_rate_cents].minimum.as("finance_rate_cents")
l1_select << "array_agg(DISTINCT CAST(offer_type AS int)) AS offer_types"
l1_select << offers[:score].maximum.as("score")
Offer.select(l1_select).group(:car_series_id, :manufacturer_name, :car_series_name, :image_public_id)
但是现在我想使用ROM重写它。我进行了大部分选择,但无法通过array_agg(DISTINCT...
部分来解决。
这是我现有的代码:
select {
[
:car_series_id,
:manufacturer_name,
:car_series_name,
:image_public_id,
int::min(:finance_rate_cents).as(:finance_rate_cents),
int::max(:score).as(:score),
]
}.group(:car_series_id, :manufacturer_name, :car_series_name, :image_public_id).to_a
如何在这里的select中使用array_agg?