Better visitable section
Andrew
committed Feb 26, 2018
commit 43671b6d4b0d04d11a25ed9ac9af48cdc969ba91
Showing 1
changed file with
11 additions
and 13 deletions
README.md
+11
-13
| @@ | @@ -131,19 +131,7 @@ See the [API spec](#api-spec). |
| ### Associated Models | |
| - | Say we want to associate orders with visits. Ahoy can do this automatically. |
| - | |
| - | First, generate a migration and add a `visit_id` column (not needed for Mongoid). |
| - | |
| - | ```ruby |
| - | class AddVisitIdToOrders < ActiveRecord::Migration[5.1] |
| - | def change |
| - | add_column :orders, :visit_id, :bigint |
| - | end |
| - | end |
| - | ``` |
| - | |
| - | Then, add `visitable` to the model. |
| + | Say we want to associate orders with visits. Ahoy can do this automatically. Just add `visitable` to the model. |
| ```ruby | |
| class Order < ApplicationRecord | |
| @@ | @@ -161,6 +149,16 @@ Order.joins(:visit).group("city").count |
| Order.joins(:visit).group("device_type").count | |
| ``` | |
| + | Here’s what the migration to add the `visit_id` column should look like: |
| + | |
| + | ```ruby |
| + | class AddVisitIdToOrders < ActiveRecord::Migration[5.1] |
| + | def change |
| + | add_column :orders, :visit_id, :bigint |
| + | end |
| + | end |
| + | ``` |
| + | |
| Customize the column and class name with: | |
| ```ruby | |