Sha256: 52effae8c2a1981b2c7446825c4bdc3f02493a1232aaaf172bb309c943152e7c
Contents?: true
Size: 1.56 KB
Versions: 8
Compression:
Stored size: 1.56 KB
Contents
class Result include Mongoid::Document include Mongoid::Timestamps #include Mongoid::History::Trackable include Model::MongoDb::Customizable include Model::MongoDb::Commentable #embedded_in :task belongs_to :task # cached associations belongs_to :story field :offeror_id, type: Integer field :user_id, type: Integer field :name, type: String field :text, type: String field :state, type: String attr_accessible :task_id, :name, :text validates :task_id, presence: true validates :story_id, presence: true validates :offeror_id, presence: true validates :text, presence: true after_initialize :cache_associations before_validation :cache_associations after_create :set_tasks_result_association after_destroy :unset_tasks_result_association #track_history on: [:name, :text, :state], scope: :task # belongs_to (SQL) def offeror; offeror_id ? User.find(offeror_id) : nil; end def offeror=(value); self.offeror_id = value.id; end def user; user_id ? User.find(user_id) : nil; end def user=(value); self.user_id = value.id; end private def cache_associations self.story_id = task.story_id if task_id.present? && (task rescue nil) self.offeror_id = task.offeror_id if task_id.present? && (task rescue nil) end def cache_product_association self.product_id = task.product_id if task_id.present? && (task rescue nil) end def set_tasks_result_association; task.update_attribute(:result_id, id); end def unset_tasks_result_association; task.update_attribute(:result_id, nil); end end
Version data entries
8 entries across 8 versions & 1 rubygems