aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/fixtures/topic.rb
blob: 55c94e9e8829c9d1023858c8415db9ea971fadaa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Topic < ActiveRecord::Base
  has_many :replies, :foreign_key => "parent_id"
  serialize :content
  
  before_create  :default_written_on
  before_destroy :destroy_children #'self.class.delete_all "parent_id = #{id}"'

  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