【发布时间】:2011-05-29 15:02:37
【问题描述】:
我有一个带有 cached_info 字段的 City 模型,它是一个序列化的哈希。
{:population=>20000, :more_stuff =>....}
如果我在 Activerecord 中进行以下查询。
City.where('cached_info[:population] > 300').count
我回来了……
ActiveRecord::StatementInvalid: Mysql2::Error:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near '[:population] > 300)' at line 1: SELECT COUNT(*) FROM `places` WHERE `places`.`type` = 'City' AND (cached_info[:population] > 3)
有人有解决方法吗?
【问题讨论】:
-
以后不要在数据库中存储哈希值 ;) 努力学习吧?
标签: sql ruby-on-rails ruby activerecord