simplifies parent/child preview code; fixes #1489

This commit is contained in:
Toks
2013-04-30 14:54:40 -04:00
parent a2cf238f58
commit 6c3aabf2b6
4 changed files with 34 additions and 14 deletions

View File

@@ -0,0 +1,24 @@
module PostSets
class PostRelationship < PostSets::Post
attr_reader :parent, :children
def initialize(parent_id, options = {})
@parent = ::Post.where("id = ?", parent_id)
@children = ::Post.where("parent_id = ?", parent_id).order("id ASC")
if options[:include_deleted]
super("parent:#{parent_id} status:any")
else
@children = @children.where("is_deleted = ?", false)
super("parent:#{parent_id}")
end
end
def posts
@parent + @children
end
def presenter
::PostSetPresenters::Post.new(self)
end
end
end