1
從config/mongoid.yml
文件中看不到identity_map
設置。Mongoid Identity Map設置在Rails控制檯中不起作用
這裏的文件:
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。
Mongoid文檔似乎直接違背了你的斷言:':options'不應該嵌套在':default'中:http://mongoid.org/en/mongoid/docs/installation.html。 – cbmanica 2013-05-30 23:04:21
@cbmanica有多種選項可以設置,我編輯我的答案突出顯示。在[documentation](http://mongoid.org/en/mongoid/docs/installation.html)中查看「Mongoid配置剖析」部分,瞭解多個選項設置的多個選項的示例。 – jwieringa 2013-05-31 23:57:16