lib/sojourn/event.rb in sojourn-0.0.7 vs lib/sojourn/event.rb in sojourn-0.1.0
- old
+ new
@@ -1,14 +1,13 @@
+require_relative 'serializers/indifferent_json'
+
module Sojourn
class Event < ActiveRecord::Base
- DEFAULT_FIELDS = [:id, :sojourner_uuid, :name, :properties, :sojourn_request_id, :user_id, :created_at]
+ DEFAULT_FIELDS = %i(id sojourner_uuid name properties user_id created_at)
- belongs_to :request, foreign_key: :sojourn_request_id
belongs_to :user
- has_one :campaign, through: :request
- has_one :browser, through: :request
- serialize :properties
+ serialize :properties, Serializers::IndifferentJSON
before_save do
properties.keys.map(&:to_sym).each do |key|
send("#{key}=", properties[key]) if self.class.available_fields.include?(key)
end