Recursively download the download yourself?

I have my own model:

class Comment < ActiveRecord::Base
     belongs_to :parent, :class_name => 'Comment', :foreign_key => 'parent_id'
     has_many :children, :class_name => 'Comment', :foreign_key => "parent_id"
end

Later, I want to make 1 sql call first to capture all the relevant comments and then display them recursively.

How do I recursively load a download?

comments = Comment.where(:post_id => @post_id).includes(:comments=> [:comments => [:comments .... #How do I get this to recursively eager load?

def show_comments(comment)
   render comment
   comment.children.each do |child|
       show_comments(child)
   end
end
+5
source share
1 answer

You can create a method that retrieves the deep nesting of identifiers, load them, and the rails will use it as a cache.

+3
source

All Articles