2

我最近开始使用 code rails,我需要弄清楚这个问题。

%td
  =  Ahoy::Event.where(name: "viewed_brochure").where_properties(brochure_id: brochure.id).select(:session_id).uniq

这应该在属性字段中找到 session_id 的不同值的数量,但它不起作用。

此行返回这些和类似的错误

#<Ahoy::Event::ActiveRecord_Relation:0x007f52d9325130>
#<Ahoy::Event::ActiveRecord_Relation:0x007f52d9466508>

%td
  =  Ahoy::Event.select { |event| event.properties['session_id'] }.uniq.count

我试过这条线,但这次返回表中的行数

4

2 回答 2

2

您可以尝试按 jsonb 键分组,在您的情况下为 properties['session_id']

Ahoy::Event.group("properties -> 'session_id'").count

这将返回您可以应用 .size 或者您可以做不同的计数。

于 2017-11-08T11:33:33.610 回答
0

非常感谢@Anton 我修改了你的解决方案,最后它工作正常。

这是解决方案

%td
  =  Ahoy::Event.where_properties(brochure_id: brochure.id).group("properties -> 'session_id'").count.size
于 2017-11-08T10:58:46.653 回答