我有Notification
模型与notification_objects
参数。 Notification.first.notification_objects
返回散列数组。我创建了一个@notification_objects
变量,它包含具有相同键/值对的散列数组(除了使用符号而不是键的字符串)。如何使用Notification.where()
找到第一个Notification
?将@notification_objects中的键字符串化不起作用。我使用的是Postgres 9.4和Rails 4.2。问题与轨道活动记录查询与JSON参数
[18] pry(main)> Notification.first.notification_objects
=> [{"class_name"=>"Ad", "ar_object_id"=>1}]
[19] pry(main)> @notification_objects
=> [{:class_name=>"Ad", :ar_object_id=>1}]
# both as_json and to_json do not work here:
[20] pry(main)> Notification.where(notification_objects: @notification_objects.as_json)
=> []
[21] pry(main)> @notification_objects.as_json
=> [{"class_name"=>"Ad", "ar_object_id"=>1}]
[22] pry(main)> Notification.first.notification_objects.as_json == @notification_objects.as_json
=> true
? 'notification_object'是db中的一个String类型? – NickGnd
使用Postgres 9.4 – user3809888