Sha256: 72577dccb5087248df6c1dffa8d0f4f8e90620b04f320da051de345854a46b76

Contents?: true

Size: 456 Bytes

Versions: 5

Compression:

Stored size: 456 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
  
  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

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-1.14.0 test/fixtures/topic.rb
activerecord-1.14.2 test/fixtures/topic.rb
activerecord-1.14.1 test/fixtures/topic.rb
activerecord-1.14.3 test/fixtures/topic.rb
activerecord-1.14.4 test/fixtures/topic.rb