Skip to content

Instantly share code, notes, and snippets.

@almaron
Created June 10, 2014 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almaron/5739bfb6acc9a05b79a6 to your computer and use it in GitHub Desktop.
Save almaron/5739bfb6acc9a05b79a6 to your computer and use it in GitHub Desktop.
Can anyone help me simplify this?
#forum.rb
def get_all_posts
forums = self.subtree_ids
topics = Topic.where(forum_id: forums).collect(&:id)
posts = Post.where(topic_id: topics)
end
# Forum has_many :topics and has_ancestry
# Topic has_many :posts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment