Mongoid Identity_map 对于 Web 请求打开,但对于后台或 rake 任务关闭?
有没有办法为 Web 请求打开 Identity_map,但在控制台或 rake 任务中默认关闭?这似乎一直让我绊倒。
这是针对 mongoid 和 Rails 的。
Is there a way to have identity_map on for web requests, but off by default in the console or in rake tasks? This seems to keep tripping me up.
This is for mongoid and rails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您升级到 mongoid 3.0.0.rc,则可以重写 using_identity_map 方法来提供您想要的内容。
买者自负。
config/initializers/identity_map.rb
Gemfile
请注意,3.0.0 的配置文件有显着不同,
并且默认模板当前仅设置开发
并且缺少测试和生产部分。
using_identity_map方法在3.0.0之前不可用,例如2.4.10,
您必须通过 .irbrc 或 Rakefile 显式重置 identity_map_enabled。
If you move up to mongoid 3.0.0.rc, then the method using_identity_map can be overridden to provide what you want.
Caveat emptor.
config/initializers/identity_map.rb
Gemfile
Note that the config file for 3.0.0 is significantly different,
and that the default template currently sets up development only
and is missing sections for test and production.
The using_identity_map method is not available prior to 3.0.0, e.g., 2.4.10,
where you will have to reset identity_map_enabled explicitly via .irbrc or Rakefile.