2013-08-04 10:59:25 +08:00
# fq
2013-08-01 10:33:49 +08:00
class JournalsForMessage < ActiveRecord :: Base
attr_accessible :jour_id , :jour_type , :notes , :reply_id , :status , :user_id
attr_accessor :indice
belongs_to :jour , :polymorphic = > true
belongs_to :user
2013-12-04 21:24:52 +08:00
has_many :acts , :class_name = > 'Activity' , :as = > :act , :dependent = > :destroy
after_create :act_as_activity #huang
2013-08-01 10:33:49 +08:00
def self . delete_message ( message_id )
self . delete_all " id = #{ message_id } "
end
2013-08-06 22:26:52 +08:00
def reference_user
User . find ( reply_id )
end
def self . reference_message ( user_id )
@user = User . find ( user_id )
2013-08-11 10:36:55 +08:00
message = JournalsForMessage . find_by_sql ( " select * from journals_for_messages where reply_id = #{ @user . id } or (jour_type = 'Bid' and jour_id in (select id from bids where author_id = #{ @user . id } )) " )
2013-08-06 22:26:52 +08:00
message
end
2013-12-04 21:24:52 +08:00
def act_as_activity
2013-12-09 16:01:50 +08:00
if self . jour_type == 'Principal'
unless self . user_id == self . jour . id && self . user_id != self . reply_id
self . acts << Activity . new ( :user_id = > self . user_id )
end
2013-12-04 21:24:52 +08:00
end
end
2013-08-01 10:33:49 +08:00
end