2

I am using Ahoy for tracking in my web app. 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.

I can join the two tables using Visit.joins(:ahoy_events) but Visit.joins(:@events) gives an error, as expected. How do I do this?

a3y3
  • 1,025
  • 2
  • 10
  • 34

1 Answers1

0

I think I got it. Variables are not allowed in a joins() query, hence I used this

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.

a3y3
  • 1,025
  • 2
  • 10
  • 34