Permalink
Browse files

Added EventEntity model.

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

0 comments on commit bfe7d5a

Please sign in to comment.