title: Querying Ahoy Gem Events
body: <p>I am using the Ahoy gem in a Rails 4.2 app. Ahoy Events stores events with a number of text attributes and a <code>properties</code> attribute that contains data I want to query. For example here is the last event I return via the rails console</p>
  
  <p><code>&gt;&gt; Ahoy::Event.last
    Ahoy::Event Load (3.8ms)  SELECT  "ahoy_events".* FROM "ahoy_events"  ORDER BY "ahoy_events"."id" DESC LIMIT 1
  =&gt; #&lt;Ahoy::Event id: "fffff17f-44e6-41d7-9c32-fa895338f54e", visit_id: "6b05b1ca-3863-46da-9c48-a3ab5fa4a9ee", user_id: 1, name: "$click", properties: {"tag"=&gt;"a", "page"=&gt;"/conversations/2", "text"=&gt;"View", "href"=&gt;"/conversations/2"}, time: "2015-08-23 13:25:51"&gt;</code></p>
  
  <p>How would I retrieve all events where properties['text'] = 'View'</p>
  
  <p>I have tried <code>Ahoy::Event.where(:properties['text'] =&gt; 'View').count</code></p>
  
  <p>which returns: 
  ```</p>
  
  <blockquote>
    <blockquote>
      <p>Ahoy::Event.where(:properties['text'] => 'View').count
      NoMethodError: undefined method <code>to_sym' for nil:NilClass
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/sanitization.rb:59:in</code>block in expand_hash_conditions_for_aggregates'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/sanitization.rb:58:in <code>each'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/sanitization.rb:58:in</code>expand_hash_conditions_for_aggregates'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/relation/query_methods.rb:957:in <code>build_where'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/relation/query_methods.rb:584:in</code>where!'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/relation/query_methods.rb:574:in <code>where'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/querying.rb:10:in</code>where'
          from (irb):13
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:in <code>start'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in</code>start'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in <code>console'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in</code>run_command!'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in <code>&lt;top (required)&gt;'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in</code>require'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in <code>block in require'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in</code>load_dependency'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in <code>require'
          from /Users/dariusgoore/development/blackops/bin/rails:8:in</code>'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in <code>load'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in</code>block in load'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in <code>load_dependency'
          from /Users/dariusgoore/development/blackops/.bundle/gems/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:268:in</code>load'
          from /Users/dariusgoore/.rubies/ruby-2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in <code>require'
          from /Users/dariusgoore/.rubies/ruby-2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in</code>require'
      ```</p>
    </blockquote>
  </blockquote>
  
  <p>I have looked online for querying hash attributes without success. Any guidance is much appreciated.</p>