Globally Reuse ActiveRecord Queries across Models? <p>Not sure how to word the question concisely :).</p> <p>I have say 20 Posts per page, and each Post has 3-5 tags. If I show all the tags in the sidebar (<code>Tag.all.each...</code>), then is there any way to have a call to <code>post.tags</code> not query the database and just use the tags found from <code>Tag.all</code>?</p> <pre><code>class Post &lt; ActiveRecord::Base end class Tag &lt; ActiveRecord::Base end </code></pre> <p>This is how you might use it:</p> <pre><code># posts_controller.rb posts = Post.all # posts/index.html.haml - posts.each do |post| render :partial =&gt; "posts/item", :locals =&gt; {:post =&gt; post} # posts/_item.html.haml - post.tags.each do |tag| %li %a{:href =&gt; "/tags/#{tag.name}"}= tag.name.titleize </code></pre> <p>I know about the following optimizations already:</p> <ol> <li>Rendering partials using <code>:collection</code></li> <li>Eager loading with <code>Post.first(:include =&gt; [:tags])</code></li> </ol> <p>I'm wondering though, if I use <code>Tag.all</code> in my <code>shared/_sidebar.haml</code> template, is there anyway to reuse the result from that query in the <code>post.tags</code> calls?</p>