似乎没有从文件identity_map
中获取设置。config/mongoid.yml
这是文件:
development:
sessions:
default:
uri: mongodb://localhost:27017/test_development
options: &defaultopts
op_timeout: 60
allow_dynamic_fields: false
identity_map_enabled: true
preload_models: true
raise_not_found_error: false
运行时RAILS_ENV=development rails console
,地图未打开:
$ RAILS_ENV=development rails c
Loading development environment (Rails 3.2.13)
[1] pry(main)> Mongoid.using_identity_map?
=> false
[2] pry(main)> Mongoid.identity_map_enabled?
=> false
即使尝试手动加载Mongoid
并且文件也不会更改它:
[3] pry(main)> require 'mongoid'
=> false
[4] pry(main)> Mongoid.load!("./config/mongoid.yml")
=> {"sessions"=>
{"default"=>
{"uri"=>"mongodb://localhost:27017/test_development",
"options"=>
{"op_timeout"=>60,
"allow_dynamic_fields"=>false,
"identity_map_enabled"=>true,
"preload_models"=>true,
"raise_not_found_error"=>false}}}}
[5] pry(main)> Mongoid.using_identity_map?
=> false
[6] pry(main)> Mongoid.identity_map_enabled?
=> false
只有当我手动设置该值时,它才会生效:
[8] pry(main)> Mongoid.identity_map_enabled = true
=> true
[9] pry(main)> Mongoid.using_identity_map?
=> true
[10] pry(main)> Mongoid.identity_map_enabled?
=> true
为什么设置没有正确加载?
使用 Rails 3.2.13 和 Mongoid 3.1.2 会出现此问题。