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?&nbsp; Is this a known limitation or am I missing something?<br><br>Many thanks,<br>Robert Head<br><br>-----<br><br>Here&#39;s my code:<br><br>class Post &lt; ActiveRecord::Base<br><br>&nbsp; # blah, blah, blah...
<br><br>&nbsp; acts_as_nested_set :left_column =&gt; &quot;lft&quot;, :right_column =&gt; &quot;rgt&quot;, :scope =&gt; :topic, :text_column =&gt; &#39;subject&#39;<br><br>&nbsp; # use faster relationships for familial relationships
<br>&nbsp; <br>&nbsp; alias nested_set_children children<br>&nbsp; has_many :children, :class_name =&gt; &quot;Post&quot;, :order =&gt; &quot;lft&quot;, :foreign_key =&gt; :parent_id<br>&nbsp; <br>&nbsp; has_many :self_and_descendants, :class_name =&gt; &quot;Post&quot;, :order =&gt; &quot;lft&quot;,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :finder_sql =&gt; &#39;SELECT * FROM posts WHERE topic_id = #{topic_id} AND (lft BETWEEN #{lft} AND #{rgt})&#39;<br>&nbsp; <br>&nbsp; alias nested_set_parent parent<br>&nbsp; belongs_to :parent, :class_name =&gt; &quot;Post&quot;, :foreign_key =&gt; :parent_id
<br><br>&nbsp; # yadda, yadda, yadda...<br><br>end<br><br>