Is it possible to execute the where-in query with datamapper?

I would like to get a list of objects that match the specified ID from datamapper .

I know that I can use several conditions or , but the list of identifiers can be in hundreds.

Is there a datamapper command that is equivalent to the following sql?

select * from table where id in (1,2,3,4,5) 
+4
source share
1 answer

You can! It will look something like this:

 users = User.all(:id => [1,2,3]) 

EDIT: you can see this on the github page for dm-core :

  # If the value of a pair is an Array, we do an IN-clause for you. Person.all(:name.like => 'S%', :id => [ 1, 2, 3, 4, 5 ]) # Does a NOT IN () clause for you. Person.all(:name.not => [ 'bob', 'rick', 'steve' ]) 
+10
source

Source: https://habr.com/ru/post/1439828/


All Articles