4

I'm using DataMapper in a Sinatra project. I'd like to be able to use a NOT LIKE stament in a DataMapper finder method, but cannot figure out how to do so.

One might imagine that this would work:

@people = People.all(:female => 1, :name.like.not => '%julie%')

...but DataMapper throws an error. Switching the order of not and like doesn't help.

Any way around this?

Jack7890
  • 1,311
  • 4
  • 19
  • 27

1 Answers1

4

According to the docs you can use subtraction to produce NOT queries:

# Subtraction produces a NOT query
Zoo.all(:state => 'IL') - Zoo.all(:tiger_count.gte => 5)
# in SQL => SELECT * FROM "zoos" WHERE 
#             ("state" = 'IL' AND NOT("tiger_count" >= 5))

Therefore the answer would seem to be:

@people = People.all(:female => 1) - People.all(:name.like => '%julie%')
Casper
  • 33,403
  • 4
  • 84
  • 79