MongoMapper 模型的取消设置操作失败,无法从模型中删除/删除密钥

发布于 2024-12-12 03:28:53 字数 1414 浏览 1 评论 0原文

我们使用的是 mongodb 2.0.0、mongo gem 1.4.1、mongo_mapper 0.9.2、rails 3.0.6。

我们喜欢 MongoMapper,但我们需要帮助解决一个棘手的问题:我们有一个从一些测试中遗留下来的密钥,但调用 obj.unset 无法执行任何操作。

具体来说,我们正在尝试删除“id”键(而不是“_id”),因为它会导致 MM 将 obj.id 视为与 obj._id 不同,这是我们不希望的。

清除数据库后,我们从不执行任何其他操作的控制器运行这些命令:(我们也尝试从 Rails 控制台运行相同的代码,但它也失败了。)

logger.info "#{Game.keys.keys.inspect}"
Game.unset({}, :id)
logger.info "#{Game.keys.keys.inspect}"
Game.unset(:id)
logger.info "#{Game.keys.keys.inspect}"

输出:

["jackpot", "players", "created_at", "puzzles", "ended_at", "player_index", "updated_at", "log", "_id", "id", "join_code", "puzzle_index"]
["jackpot", "players", "created_at", "puzzles", "ended_at", "player_index", "updated_at", "log", "_id", "id", "join_code", "puzzle_index"]
["jackpot", "players", "created_at", "puzzles", "ended_at", "player_index", "updated_at", "log", "_id", "id", "join_code", "puzzle_index"]

我们的游戏模型中定义的当前键:

  key :players, Array, :default => []
  key :player_index, Integer, :default => 0
  key :puzzles, Array, :default => []
  key :puzzle_index, Integer, :default => 0
  key :join_code, String, :default => nil
  key :jackpot, Integer, :default => 0
  key :log, Array, :default => []
  key :created_at, Time
  key :updated_at, Time
  key :ended_at, Time, :default => nil

帮助?

谢谢!

We're on mongodb 2.0.0, mongo gem 1.4.1, mongo_mapper 0.9.2, rails 3.0.6.

We love MongoMapper, but we need helping resolving one nasty issue: we have a key carried over from some testing, but invoking obj.unset fails to do anything.

Specifically, we are trying to remove an "id" key (not "_id") because it's causing MM to treat obj.id as different from obj._id, which we don't want.

After clearing out the database, we ran these commands from a controller which does nothing else: (We also tried running the same code from the rails console, but it also fails.)

logger.info "#{Game.keys.keys.inspect}"
Game.unset({}, :id)
logger.info "#{Game.keys.keys.inspect}"
Game.unset(:id)
logger.info "#{Game.keys.keys.inspect}"

Output:

["jackpot", "players", "created_at", "puzzles", "ended_at", "player_index", "updated_at", "log", "_id", "id", "join_code", "puzzle_index"]
["jackpot", "players", "created_at", "puzzles", "ended_at", "player_index", "updated_at", "log", "_id", "id", "join_code", "puzzle_index"]
["jackpot", "players", "created_at", "puzzles", "ended_at", "player_index", "updated_at", "log", "_id", "id", "join_code", "puzzle_index"]

Current keys defined in our Game model:

  key :players, Array, :default => []
  key :player_index, Integer, :default => 0
  key :puzzles, Array, :default => []
  key :puzzle_index, Integer, :default => 0
  key :join_code, String, :default => nil
  key :jackpot, Integer, :default => 0
  key :log, Array, :default => []
  key :created_at, Time
  key :updated_at, Time
  key :ended_at, Time, :default => nil

Help?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明媚殇 2024-12-19 03:28:53

发布答案让我们很痛苦,因为这巩固了我们作为“白痴、白痴、傻瓜、菜鸟、Jay Leno 粉丝”的地位,但以防万一其他人遇到同样的问题:虽然我们的模型目录在开发环境中是干净的,但生产环境中的模型目录包含旧的测试文件...其中包含带有“id”键的旧模型。

显然,删除旧文件和旧模型解决了一切,尽管我们的自尊心和头脑受到了惊人的伤害(过度撞击墙壁)。

It pains us to post the answer since this solidifies our status as "morons, idiots, fools, noobs, Jay Leno fans," but in case anyone else bumps into the same issue: while our model directory was clean in the dev environment, the model dir in the production environment contained old test files ... which contained an old model with the "id" key.

Obviously, removing the old files and the old models solved everything, though we're left with staggering bruises to our egos and to our heads (from excessive banging against the walls).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文