返回没有特定键的记录 – Rails4 HStore Postgresql查询
我有一个模型任务
t.string "name" t.hstore "actions"
例:
#"9"}, #"1"}, #<Task id: 3, name: "third", actions: nil, #"11"},
我需要找到行动的所有记录:nil,:今天<10和关键:今天不存在。 这是1,2,3任务。
Task.where("actions -> 'today' 'today' < '10' OR actions IS NULL") - it return 1 and 3 records.
我怎么能找到所有没有钥匙的记录:今天在行动?
从这里开始 ,根据你的问题:
Task.where("actions IS NULL OR EXIST(actions, 'today') = FALSE")
并根据你的意见:
Task.where("actions -> 'today' < '10' OR actions IS NULL OR EXIST(actions, 'today') = FALSE")