Sha256: b5b9ba27b634143242ba2df787eb972ff42af85fa3a6b5a7520e8fc4c4665010

Contents?: true

Size: 767 Bytes

Versions: 13

Compression:

Stored size: 767 Bytes

Contents

class Topic < ActiveRecord::Base
  has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
  serialize :content
  
  before_create  :default_written_on
  before_destroy :destroy_children

  def parent
    Topic.find(parent_id)
  end
  
  # trivial method for testing Array#to_xml with :methods
  def topic_id
    id
  end
  

  protected
    def approved=(val)
      @custom_approved = val
      write_attribute(:approved, val)
    end

    def default_written_on
      self.written_on = Time.now unless attribute_present?("written_on")
    end

    def destroy_children
      self.class.delete_all "parent_id = #{id}"
    end

    def after_initialize
      if self.new_record?
        self.author_email_address = 'test@test.com'
      end
    end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
activerecord-2.0.0 test/fixtures/topic.rb
activerecord-2.0.2 test/fixtures/topic.rb
activerecord-2.0.1 test/fixtures/topic.rb
activerecord-2.0.4 test/fixtures/topic.rb
activerecord-2.0.5 test/fixtures/topic.rb
radiant-0.6.5.1 vendor/rails/activerecord/test/fixtures/topic.rb
radiant-0.6.5 vendor/rails/activerecord/test/fixtures/topic.rb
radiant-0.6.7 vendor/rails/activerecord/test/fixtures/topic.rb
radiant-0.6.6 vendor/rails/activerecord/test/fixtures/topic.rb
radiant-0.6.9 vendor/rails/activerecord/test/fixtures/topic.rb
radiant-0.6.8 vendor/rails/activerecord/test/fixtures/topic.rb
spree-0.0.9 vendor/rails/activerecord/test/fixtures/topic.rb
spree-0.2.0 vendor/rails/activerecord/test/fixtures/topic.rb