【发布时间】:2012-01-31 17:47:02
【问题描述】:
情况是这样的。
user embed_one profile
profile belongs_to city
我已经用
填充了一个城市表id as Integer
name as String
现在我在做
user.update_attributes(:profile_attributes{:city_id=>"5"})模拟浏览器表单提交。然后我检查user.profile 我看到city_id 存储为字符串。这使我的user.profile.city 为零。
我想知道在这里做什么是正确的。我应该让我的城市 ID 是字符串还是 BSON 对象?或者我应该尝试拦截 update_attributes 以使 mongoid 商店 city_id 为整数?我使用 Integer 作为城市 id 的原因是因为我认为通过 Integer 搜索比通过字符串搜索更快。而且我有州和城市表,我想以可预测的方式匹配 ID,所以我不想使用 BSON 随机键。
【问题讨论】:
标签: ruby ruby-on-rails-3 mongoid