I recently implemented better_nested_set in a forum project and found that every time I called parent, full_set, all_children, or children, the DB got hit again.<br><br>To fix this I overrode those methods as has_many and belongs_to relationships, which are, apparently, cached by ActiveRecord.
<br><br>Why no caching? Is this a known limitation or am I missing something?<br><br>Many thanks,<br>Robert Head<br><br>-----<br><br>Here's my code:<br><br>class Post < ActiveRecord::Base<br><br> # blah, blah, blah...
<br><br> acts_as_nested_set :left_column => "lft", :right_column => "rgt", :scope => :topic, :text_column => 'subject'<br><br> # use faster relationships for familial relationships
<br> <br> alias nested_set_children children<br> has_many :children, :class_name => "Post", :order => "lft", :foreign_key => :parent_id<br> <br> has_many :self_and_descendants, :class_name => "Post", :order => "lft",
<br> :finder_sql => 'SELECT * FROM posts WHERE topic_id = #{topic_id} AND (lft BETWEEN #{lft} AND #{rgt})'<br> <br> alias nested_set_parent parent<br> belongs_to :parent, :class_name => "Post", :foreign_key => :parent_id
<br><br> # yadda, yadda, yadda...<br><br>end<br><br>