Project

General

Profile

Defect #5354 » scvmc_project_cf_updated_on_r3.diff

Patch which corrects the issue against trunk r4093, using callbacks within model - Stuart Cianos, 2010-09-17 02:45

View differences:

app/models/custom_value.rb (working copy)
18 18
class CustomValue < ActiveRecord::Base
19 19
  belongs_to :custom_field
20 20
  belongs_to :customized, :polymorphic => true
21
  after_update :after_save_value
21 22

  
22 23
  def after_initialize
23 24
    if new_record? && custom_field && (customized_type.blank? || (customized && customized.new_record?))
24 25
      self.value ||= custom_field.default_value
25 26
    end
26 27
  end
28

  
29
  # Update the parent project's updated on timestamp if the custom value
30
  # attached to it has changed. This has been abstracted using callbacks
31
  # due to a bug that causes :touch => true to hang on
32
  # the polymorphic association.
33
  def after_save_value
34
    return unless self.changed?
35
    if customized_type == "Project"
36
      self.customized.touch
37
    end
38
  end
27 39
  
28 40
  # Returns true if the boolean custom value is true
29 41
  def true?
(3-3/5)