title: Querying the Ahoy gem properties hash
body: <p>I am using the Ahoy gem to record user actions in a Rails 4 app. Events are being recorded and stored in the Ahoy::Event table. Each event has a <code>properties</code> hash attribute stored as text. In this case, am trying to return the number of article views for a specific article.</p>
  
  <p>I am following the suggested syntax in the gem docs here: <a href="https://github.com/ankane/ahoy#querying-properties" rel="nofollow">https://github.com/ankane/ahoy#querying-properties</a>, which gives an example of <code>Ahoy::Event.where("properties LIKE '%\"store_id\": \"1\"%'").count</code> for querying a properties text hash, but I have been unable to return accurate results.</p>
  
  <p>Here is the controller event I am tracking to test this:</p>
  
  <p><code>
  def show
    @article = Article.friendly.find(params[:id])
    ...
    ahoy.track "Viewed article", article_id: @article.id
    ...
  end
  </code></p>
  
  <p>In console, as expected I can see one event is returned when I search for articles with the name: "Viewed Article":</p>
  
  <p><code>
   Ahoy::Event.where(name: "Viewed article")
    Ahoy::Event Load (89.1ms)  SELECT "ahoy_events".* FROM "ahoy_events" WHERE "ahoy_events"."name" = $1  [["name", "Viewed article"]]
  =&gt; #&lt;ActiveRecord::Relation [#&lt;Ahoy::Event id: "6cda3790-625d-4b73-8ef0-262a26b29618", visit_id: "2d56efa6-3590-4a64-acec-c0fd0ba07727", user_id: nil, name: "Viewed article", properties: {"article_id"=&gt;562}, time: "2016-06-03 18:49:28"&gt;]&gt;
  </code></p>
  
  <p>But when I attempt to find the same event by querying for events with the corresponding article_id, the event is not found:</p>
  
  <p><code>
   Ahoy::Event.where("properties LIKE '%\"article_id\": \"562\"%'").count
     (207.5ms)  SELECT COUNT(*) FROM "ahoy_events" WHERE (properties LIKE '%"article_id": "562"%')
  =&gt; 0
  </code></p>
  
  <p>Any suggestions are much appreciated.</p>