Querying many tuples with composite key

What is the easiest way to query many tuples with composite key in ROM SQL?
Given a dataset with say (product_id, position) and an array of tuples

  { product_id: 10, position: 1},
  { product_id: 11, position: 2}

I am looking for the easiest way to query only those tuples, that match both values. Obviously this is a disjunction of many conjunctions, but I haven’t found how to query for it in a canonical way.

Shall I build a query like that:

tuples[1..].inject(dataset.where(tuples[0])) { |q, t| q.or(t) }


@apohllo yep that’s more or less what I’ve done in the past. We could have a helper method for this common scenario.

Ok, thanks. Actually this should be corrected, in the case the array has only one element:

(tuples[1..] || []).inject(dataset.where(tuples[0])) { |q, t| q.or(t) }
1 Like


tuples.drop(1).inject(dataset.where(tuples[0])) { |q, t| q.or(t) }