简体   繁体   English

Ahoy Ruby on Rails-联接表(访问和事件)

[英]Ahoy Ruby on Rails- join tables (Visit and Event)

I am using Ahoy for tracking in my web app. 我正在使用Ahoy在我的Web应用程序中进行跟踪。 I find events with this: 我发现与此相关的事件:

@events = Ahoy::Event.where_properties(title: params[:token])

and I want to get all Visits having visit ID that the above relation, @events, has. 我想获得具有上述关系@events的所有访问ID的所有访问。

I can join the two tables using Visit.joins(:ahoy_events) but Visit.joins(:@events) gives an error, as expected. 我可以使用Visit.joins(:ahoy_events) but将两个表连接起来, Visit.joins(:ahoy_events) but Visit.joins(:@events)给出了一个错误,与预期的一样。 How do I do this? 我该怎么做呢?

I think I got it. 我想我明白了。 Variables are not allowed in a joins() query, hence I used this joins()查询中不允许使用变量,因此我使用了这个

def show
    @events = Ahoy::Event.where_properties(title: params[:token])
    @visits = Visit.joins(:ahoy_events).where(:ahoy_events=>{:properties => {title: params[:token]}})
end

And it seems to be working. 它似乎正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM