This commit is contained in:
Toks
2013-09-09 20:36:43 -04:00
parent b2b685a251
commit d9419255f6

View File

@@ -18,6 +18,7 @@ class Post < ActiveRecord::Base
before_validation :initialize_uploader, :on => :create
before_validation :parse_pixiv_id
before_validation :blank_out_nonexistent_parents
before_validation :remove_parent_loops
belongs_to :updater, :class_name => "User"
belongs_to :approver, :class_name => "User"
belongs_to :uploader, :class_name => "User"
@@ -814,6 +815,13 @@ class Post < ActiveRecord::Base
end
end
def remove_parent_loops
if parent.present? && parent.parent_id == id
parent.parent_id = nil
parent.save
end
end
def validate_parent_does_not_have_a_parent
return if parent.nil?
if !parent.parent.nil?