如何使用DataMapper` NOT LIKE`子句?

时间:2013-01-16 22:46:10

标签: ruby database orm sinatra datamapper

我在Sinatra项目中使用DataMapper。我希望能够在DataMapper finder方法中使用NOT LIKE stament,但无法弄清楚如何操作。

有人可能会想到这会奏效:

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

...但DataMapper会抛出错误。切换notlike的顺序无济于事。

有什么方法吗?

1 个答案:

答案 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%')