title: Query in Active record with an array of hash
body: <p>I have the following model in Ruby</p>
  
  <pre><code>class Entity &lt; ActiveRecord::Base
    validates :account_type, presence: true
    validates :account_id, presence: true
  end
  </code></pre>
  
  <p>and I have an array of hashes called accounts something like:</p>
  
  <pre><code>[{'account_id':44, 'account_type':'user'},..,{'account_id':44, 'account_type':'other'}, {'account_id':88,
  'account_type':'another'}]
  </code></pre>
  
  <p>So I want a way to obtain all the entities that match with the elements of the accounts array (account_id and
  account_type both at same time).</p>
  
  <p>I tried using this code:</p>
  
  <pre><code>entities = []
  accounts.each do |account|
      entities &lt;&lt; Entity.where(account_id: ActiveSupport::HashWithIndifferentAccess.new(account)['account_id'])
      .where(account_type: ActiveSupport::HashWithIndifferentAccess.new(account)['account_type'])
  end
  </code></pre>
  
  <p>But there is a way to do it more efficient ??</p>