【发布时间】:2017-04-03 21:30:24
【问题描述】:
我需要查找类型采访用户的所有通知。
app/models/notification.rb:
class Notification < ActiveRecord::Base
belongs_to :user
hstore_accessor(
:data,
path: :string,
message: :string,
type: :string
)
end
在 google 中搜索并没有太多信息,所以 我关注了this tutorial:但无法按照示例中的说明查询数据库:
User.where("preferences -> newsletter = :value", value: 'true')
我试过了
user.notifications.where('data -> type = :key', key: Interview::NOTIFICATION_TYPE)
但我得到了错误:
*** ActiveRecord::StatementInvalid Exception: PG::UndefinedColumn: ERROR: column "type" does not exist
LINE 1: ...WHERE "notifications"."user_id" = $1 AND (data -> type = 'IN...
^
: SELECT COUNT(*) FROM "notifications" WHERE "notifications"."user_id" = $1 AND (data -> type = 'INTERVIEW')`
【问题讨论】:
标签: ruby-on-rails postgresql-9.1 hstore