我有一个带有cached_info字段的City模型,它是一个序列化的散列。Activerecord带有散列值的地方
{: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)
任何人对此有一个解决方法吗?
不要存放哈希在未来的数据库;)了解硬盘的方式,不是吗? – d11wtq 2011-05-29 15:11:15