我有一個帶有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