title: Remove duplicate in ActiveRecord habtm query results
body: <p>I have two models has_and_belong_to_many to each other:</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    has_and_belongs_to_many :tags, :join_table =&gt; :tags_posts
  end
  
  class Tag &lt; ActiveRecord::Base
    has_and_belongs_to_many :posts, :join_table =&gt; :tags_posts
  end
  </code></pre>
  
  <p>And then I have a query:</p>
  
  <pre><code>@tags = Tag.where(name: ["tag1","tag2","tag3"])
  </code></pre>
  
  <p>I want to get all the unique posts that have these tags, so I write this ugly code:</p>
  
  <pre><code>@posts = [] 
  @tags.each do |tag|
    @posts += tag.posts
  end
  @posts.uniq!
  </code></pre>
  
  <p>I guess it's inefficient, and since @posts is an array rather than a "ActiveRecord::Relation", I can't use all the class methods on it directly.
  Is there a better way to achieve this? </p>