我在Sinatra项目中使用DataMapper。我希望能够在DataMapper finder方法中使用NOT LIKE
stament,但无法弄清楚如何操作。
有人可能会想到这会奏效:
@people = People.all(:female => 1, :name.like.not => '%julie%')
...但DataMapper会抛出错误。切换not
和like
的顺序无济于事。
有什么方法吗?
答案 0 :(得分:4)
根据to the docs,您可以使用减法来生成NOT
个查询:
# 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))
因此答案似乎是:
@people = People.all(:female => 1) - People.all(:name.like => '%julie%')