app/models/result.rb in voluntary-0.5.2 vs app/models/result.rb in voluntary-0.6.0
- old
+ new
@@ -21,11 +21,11 @@
attr_accessible :task_id, :name, :text
validates :task_id, presence: true
validates :story_id, presence: true
- validates :offeror_id, presence: true
+ validates :offeror_id, presence: true, if: 'task_id.present? && (task rescue nil) && task.story.with_offeror'
validates :text, presence: true
after_initialize :cache_associations
before_validation :cache_associations
after_create :set_tasks_result_association
@@ -46,15 +46,15 @@
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)
+ self.offeror_id = task.offeror_id if task_id.present? && (task rescue nil) && task.story.with_offeror
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
+ def set_tasks_result_association; task.update_attribute(:result_id, id) unless task.respond_to?(:results); end
+ def unset_tasks_result_association; task.update_attribute(:result_id, nil) unless task.respond_to?(:results); end
end
\ No newline at end of file