Rails N+1 because of .joins?
<p>I got a simple search for posts in my rails app. It searches through taggings of the post and the content (body) of the post. Everything works finde, but bullet moans about a N+1 query. </p>

<pre><code>N+1 Query detected Post =&gt; [:tags] Add to your finder: :includes =&gt; [:tags]
</code></pre>

<p>How can I avoid that in my situation? Code looks like that:</p>

<p><strong>model</strong></p>

<pre><code>  def self.search(search)
    Post.joins(:tags).where("name LIKE ? or body LIKE ?", "%#{search}%", "%#{search}%").uniq
  end
</code></pre>

<p><strong>controller</strong></p>

<pre><code>  def index
    if params[:search]
      @posts = Post.includes(:author).search(params[:search])
    else
      @posts = Post.includes(:author, :tags).all
    end
  end
</code></pre>

<p>If i use .includes instead of .joins, I get the following:</p>

<pre><code>SQLite3::SQLException: no such column: name:
</code></pre>

<p>so, as a beginner, how to deal with that? Are there better solutions? Thank you in advance!</p>