mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
d0696d7641
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4909 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
25 lines
544 B
Ruby
Executable file
25 lines
544 B
Ruby
Executable file
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 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
|