Skip to content
This repository
Browse code

Added EventEntity model.

  • Loading branch information...
commit bfe7d5afd333d617dceefcde08833217eb5b8775 1 parent e6d86b0
Slobodan Kovacevic basti authored
4 app/models/event_entity.rb
... ... @@ -0,0 +1,4 @@
  1 +class EventEntity < ActiveRecord::Base
  2 + belongs_to :event_log
  3 + belongs_to :entity, :polymorphic => true # person, community, ... anyone and anything related to the event
  4 +end
2  app/models/event_log.rb
@@ -20,6 +20,8 @@ class EventLog < ActiveRecord::Base
20 20 belongs_to :action_object, :polymorphic => true # e.g. item
21 21 belongs_to :related, :polymorphic => true # e.g. item_request
22 22 belongs_to :event_type
  23 +
  24 + has_many :event_entities
23 25
24 26 validates_presence_of :primary_id, :primary_type, :primary_short_name, :primary_full_name
25 27 validates_presence_of :action_object_id, :action_object_type, :action_object_type_readable
7 app/models/person.rb
@@ -9,10 +9,13 @@ class Person < ActiveRecord::Base
9 9 has_many :received_people_networks, :class_name => "PeopleNetwork", :foreign_key => "trusted_person_id"
10 10
11 11 has_many :activity_logs, :as => :primary
12   - has_many :activity_logs_as_secondary, :as => :secondary
  12 + has_many :activity_logs_as_secondary, :as => :secondary, :class_name => "ActivityLog"
13 13
14 14 has_many :event_logs, :as => :primary
15   - has_many :event_logs_as_secondary, :as => :secondary
  15 + has_many :event_logs_as_secondary, :as => :secondary, :class_name => "EventLog"
  16 +
  17 + has_many :event_entities, :as => :entity
  18 + has_many :related_event_logs, :through => :event_entities, :source => :event_log
16 19
17 20 validates_presence_of :user_id, :name
18 21
17 db/migrate/20110323205943_create_event_entities.rb
... ... @@ -0,0 +1,17 @@
  1 +class CreateEventEntities < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :event_entities do |t|
  4 + t.integer :event_log_id
  5 + t.integer :entity_id
  6 + t.string :entity_type
  7 + t.timestamps
  8 + end
  9 +
  10 + add_index(:event_entities, :event_log_id)
  11 + add_index(:event_entities, [:entity_id, :entity_type])
  12 + end
  13 +
  14 + def self.down
  15 + drop_table :event_entities
  16 + end
  17 +end
13 db/schema.rb
@@ -10,7 +10,7 @@
10 10 #
11 11 # It's strongly recommended to check this file into your version control system.
12 12
13   -ActiveRecord::Schema.define(:version => 20110323204226) do
  13 +ActiveRecord::Schema.define(:version => 20110323205943) do
14 14
15 15 create_table "activity_logs", :force => true do |t|
16 16 t.integer "event_code"
@@ -33,6 +33,17 @@
33 33 add_index "activity_logs", ["event_code"], :name => "index_activity_logs_on_event_code"
34 34 add_index "activity_logs", ["primary_id", "primary_type"], :name => "index_activity_logs_on_primary_id_and_primary_type"
35 35
  36 + create_table "event_entities", :force => true do |t|
  37 + t.integer "event_log_id"
  38 + t.integer "entity_id"
  39 + t.string "entity_type"
  40 + t.datetime "created_at"
  41 + t.datetime "updated_at"
  42 + end
  43 +
  44 + add_index "event_entities", ["entity_id", "entity_type"], :name => "index_event_entities_on_entity_id_and_entity_type"
  45 + add_index "event_entities", ["event_log_id"], :name => "index_event_entities_on_event_log_id"
  46 +
36 47 create_table "event_logs", :force => true do |t|
37 48 t.integer "primary_id"
38 49 t.string "primary_type"
5 spec/models/event_entity_spec.rb
... ... @@ -0,0 +1,5 @@
  1 +require 'spec_helper'
  2 +
  3 +describe EventEntity do
  4 + pending "add some examples to (or delete) #{__FILE__}"
  5 +end

0 comments on commit bfe7d5a

Please sign in to comment.
Something went wrong with that request. Please try again.