Sha256: 68eaf2ba2fd3bab97b4b9779fb3405ea545a3fc0fb0b66538bcdbc421a76453d

Contents?: true

Size: 457 Bytes

Versions: 19

Compression:

Stored size: 457 Bytes

Contents

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

  def parent
    self.class.find(parent_id)
  end
  
  protected
    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
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
activerecord-1.13.0 test/fixtures/topic.rb
activerecord-1.11.1 test/fixtures/topic.rb
activerecord-1.11.0 test/fixtures/topic.rb
activerecord-1.12.1 test/fixtures/topic.rb
activerecord-1.10.1 test/fixtures/topic.rb
activerecord-1.10.0 test/fixtures/topic.rb
activerecord-1.12.2 test/fixtures/topic.rb
activerecord-1.13.1 test/fixtures/topic.rb
activerecord-1.13.2 test/fixtures/topic.rb
activerecord-1.2.0 test/fixtures/topic.rb
activerecord-1.4.0 test/fixtures/topic.rb
activerecord-1.3.0 test/fixtures/topic.rb
activerecord-1.5.0 test/fixtures/topic.rb
activerecord-1.5.1 test/fixtures/topic.rb
activerecord-1.8.0 test/fixtures/topic.rb
activerecord-1.6.0 test/fixtures/topic.rb
activerecord-1.7.0 test/fixtures/topic.rb
activerecord-1.9.0 test/fixtures/topic.rb
activerecord-1.9.1 test/fixtures/topic.rb