2

我正在尝试根据事件中的特定属性(“值”)找到正确的方法来获取数据库中前 5 个(按计数)事件。我还使用 hightop gem 来更容易获得前 5 名。

如果我使用:

Ahoy::Event.where(time: Date.today.beginning_of_month..Date.today.end_of_month).top(:name, 5)

这有效,但按事件名称排序。我想按该事件中的“价值”属性进行排序。典型事件如下所示:

<Ahoy::Event id: 229, visit_id: 318, user_id: 1, name: "Thing", properties: {"episode"=>"1", "title"=>"Test", "value"=>"Thing Ep 1: Test"}, time: "2017-11-02 11:34:10">

我试图这样做:

Ahoy::Event.where(time: Date.today.beginning_of_month..Date.today.end_of_month).top("properties['value']", 5)

也:

Ahoy::Event.where(time: Date.today.beginning_of_month..Date.today.end_of_month).top("properties ->> 'value'", 5)

但这会产生以下错误:“不能为文本下标,因为它不是数组”。有没有办法真正做我想做的事?

4

0 回答 0