aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/fixtures/topic.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/fixtures/topic.rb')
-rwxr-xr-xactiverecord/test/fixtures/topic.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/fixtures/topic.rb b/activerecord/test/fixtures/topic.rb
new file mode 100755
index 0000000000..55c94e9e88
--- /dev/null
+++ b/activerecord/test/fixtures/topic.rb
@@ -0,0 +1,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 \ No newline at end of file