将SQL查询转换为ActiveRecord/Arel查询

将SQL查询转换为ActiveRecord/Arel查询,sql,ruby-on-rails,sql-server,activerecord,Sql,Ruby On Rails,Sql Server,Activerecord,我有一个SQL查询 SELECT events.id FROM events JOIN flows ON flows.event_id=events.id JOIN prices ON prices.priceable_id=flows.id AND prices.priceable_type='Flow' GROUP BY events.id HAVING SUM(prices.inclusive_tax)>200; 这是预期的效果 我把它变成了一个疑问: Ev

我有一个SQL查询

SELECT 
  events.id
FROM
 events
   JOIN flows ON flows.event_id=events.id
   JOIN prices ON prices.priceable_id=flows.id AND prices.priceable_type='Flow'
GROUP BY
  events.id
HAVING SUM(prices.inclusive_tax)>200;
这是预期的效果

我把它变成了一个疑问:

Event.select('events.id').joins(:flows => :price).group('events.id').having('SUM(prices.inclusive_tax) > 200')

但我有身份证。是否可以将其转换为ActiveRecord/Arel查询,这样我就可以得到
事件
记录?

能否尝试将查询修改为以下格式。这是我通常用于报告的内容

Event.find(:all, :conditions => condition_text, :from => from_text, :select => select_text, :joins => join_text)

可能的到目前为止,您尝试了什么?
Event.select('events.id')。join(:flows=>:price)。group('events.id')。having('SUM(prices.inclusive_tax)>200')
返回
id
很好。我可以换成唱片吗?:)使用
事件。选择('*')…
事件。选择('events.*')…
而不是
事件。选择('events.id')…
,它不仅允许您从表中获取所有列
id
。这在
column“events”中失败。id在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。
。添加select
事件链。select('events.id','events.title','events.name')
等,
id
应该是select方法中的第一个,要返回记录,您应该告诉
select
get not only
events.id