2

我有一个模型任务

t.string   "name"
t.hstore   "actions"

例子:

#<Task id: 1, name: "first", actions: {"today"=>"9"}, 
#<Task id: 2, name: "second", actions: {"yesterday"=>"1"}, 
#<Task id: 3, name: "third", actions: nil,
#<Task id: 4, name: "four", actions: {"today"=>"11"},

我需要找到所有操作的记录:nil,:today<10 和 key:today 不存在。这是1,2,3任务。

Task.where("actions -> 'today' < '10'") - it return only first task.
Task.where("actions -> 'today' < '10' OR actions IS NULL")  - it return 1 and 3 records.

我怎样才能找到所有没有关键的记录:今天在行动?

4

1 回答 1

8

这里,根据你的问题:

Task.where("actions IS NULL OR EXIST(actions, 'today') = FALSE")

并根据您的评论:

Task.where("actions -> 'today' < '10' OR actions IS NULL OR EXIST(actions, 'today') = FALSE")
于 2013-07-15T02:59:05.427 回答