モンゴイド 2.4.4 レール 3.2.1 モンゴ DB 2.0.1
私は3つのモデルを持っています:
認証、お気に入り、コンテンツ。</p>
これは、認証からお気に入りを介したコンテンツへの多対多の関係のようなものです。
このようにクエリすると:
@favorites = Favorite.any_in(authentication_id: list).includes(:content, :authentication).desc(:collected_at).page params[:page]
@favorites は正常に動作します
@favorites のコンテンツも正常に機能します。
しかし、@favorites の認証には _id しかなく、他のすべてのフィールドは nil です
identity_map_enabled: false を設定すると、修正されました。
これはidentity_mapのバグですか?
tracert に関する情報を
次に示します。ID マップが有効になっていると、f.weibo.name が nil であることがわかります。
identity_map_enabled: true の場合、この問題を修正するにはどうすればよいですか?
--------------------- モデル -------------------------------- -----
class Authentication
include Mongoid::Document
include Mongoid::Timestamps
include Service::Weibo::Api::Oauth
cache
field :_id, :type => Integer
field :uid, :type => Integer
field :name, :type => String
has_many :favorites
end
class Favorite
include Mongoid::Document
include Mongoid::Timestamps
cache
paginates_per 20
field :collected_at, :type => Time, :default => Time.now
belongs_to :authentication
belongs_to :content
def weibo
self.authentication
end
def weibo_ids
self.authentication_ids
end
end
class Content
include Mongoid::Document
include Mongoid::Timestamps
cache
field :text, :type => String
has_many :favorites
end
-------------- デバッグ コード: -----------------------
logger.debug "list: #{list}"
@favorites = Favorite.any_in(authentication_id:
list).includes(:content, :authentication).desc(:collected_at).page
params[:page]
@favorites.each do |f|
logger.debug f
logger.debug "name: #{f.weibo.name}"
logger.debug "before name: #{@favorites.first.weibo.name}"
clist = [764826410]
# cf = Favorite.any_in(content_id:
clist).includes(:content, :authentication)
logger.debug "after query name: #{@favorites.first.weibo.name}"
# cf.each {|f| logger.debug "cname: #{f.weibo.name}" }
logger.debug "after logger name: #{@favorites.first.weibo.name}"
--------- デバッグコード終了 ----------------------
--------- LOG identity_map_enabled: true --------------------
[0408 12:42:38(3129)DEBUG] list: [1751951491]
15 [0408 12:42:38(3129)DEBUG] MONGODB
weibofav_development['system.namespaces'].find({})
16 [0408 12:42:38(3129)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(20).sort([[:collected_at, :desc]])
17 [0408 12:42:38(3129)DEBUG] #<Favorite _id:
4f80c04953cd210b56000003, _type: nil, created_at: 2012-04-07 22:31:37
UTC, updated_at: 2012-04-07 22:31:37 UTC, collected_at
: 2012-04-07 20:46:37 UTC, authentication_id: 1751951491,
content_id: 3418929751988429>
18 [0408 12:42:38(3129)DEBUG] name:
19 [0408 12:42:38(3129)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
20 [0408 12:42:38(3129)DEBUG] before name:
21 [0408 12:42:38(3129)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
22 [0408 12:42:38(3129)DEBUG] after query name:
23 [0408 12:42:38(3129)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
24 [0408 12:42:38(3129)DEBUG] after logger name:
25 [0408 12:42:38(3129)DEBUG] #<Favorite _id:
4f80c04953cd210b56000005, _type: nil, created_at: 2012-04-07 22:31:37
UTC, updated_at: 2012-04-07 22:31:37 UTC, collected_at
: 2012-04-07 20:46:37 UTC, authentication_id: 1751951491,
content_id: 3418840442279122>
26 [0408 12:42:38(3129)DEBUG] name:
27 [0408 12:42:38(3129)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
28 [0408 12:42:38(3129)DEBUG] before name:
29 [0408 12:42:38(3129)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
30 [0408 12:42:38(3129)DEBUG] after query name:
31 [0408 12:42:38(3129)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
32 [0408 12:42:38(3129)DEBUG] after logger name:
33 [0408 12:42:38(3129)DEBUG] #<Favorite _id:
4f80c04953cd210b56000007, _type: nil, created_at: 2012-04-07 22:31:37
UTC, updated_at: 2012-04-07 22:31:37 UTC, collected_at
: 2012-04-07 20:46:37 UTC, authentication_id: 1751951491,
content_id: 3368827987931269>
--------- LOG identity_map_enabled: false --------------------
17 [0408 12:37:53(3092)DEBUG] list: [1751951491]
18 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['system.namespaces'].find({})
19 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(20).sort([[:collected_at, :desc]])
20 [0408 12:37:53(3092)DEBUG] #<Favorite _id:
4f80c04953cd210b56000003, _type: nil, created_at: 2012-04-07 22:31:37
UTC, updated_at: 2012-04-07 22:31:37 UTC, collected_at
: 2012-04-07 20:46:37 UTC, authentication_id: 1751951491,
content_id: 3418929751988429>
21 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['authentications'].find({:_id=>1751951491}).limit(-1).sort([[:_id, :asc]])
22 [0408 12:37:53(3092)DEBUG] name: magazine
23 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
24 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['authentications'].find({:_id=>1751951491}).limit(-1).sort([[:_id, :asc]])
25 [0408 12:37:53(3092)DEBUG] before name: magazine
26 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
27 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['authentications'].find({:_id=>1751951491}).limit(-1).sort([[:_id, :asc]])
28 [0408 12:37:53(3092)DEBUG] after query name: magazine
29 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
30 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['authentications'].find({:_id=>1751951491}).limit(-1).sort([[:_id, :asc]])
31 [0408 12:37:53(3092)DEBUG] after logger name: magazine
32 [0408 12:37:53(3092)DEBUG] #<Favorite _id:
4f80c04953cd210b56000005, _type: nil, created_at: 2012-04-07 22:31:37
UTC, updated_at: 2012-04-07 22:31:37 UTC, collected_at
: 2012-04-07 20:46:37 UTC, authentication_id: 1751951491,
content_id: 3418840442279122>
33 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['authentications'].find({:_id=>1751951491}).limit(-1).sort([[:_id, :asc]])
34 [0408 12:37:53(3092)DEBUG] name: magazine
35 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
36 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['authentications'].find({:_id=>1751951491}).limit(-1).sort([[:_id, :asc]])
37 [0408 12:37:53(3092)DEBUG] before name: magazine
38 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
39 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['authentications'].find({:_id=>1751951491}).limit(-1).sort([[:_id, :asc]])
40 [0408 12:37:53(3092)DEBUG] after query name: magazine
41 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['favorites'].find({:authentication_id=>{"$in"=>[1751951491]}}).limit(-1).sort([[:collected_at, :desc]])
42 [0408 12:37:53(3092)DEBUG] MONGODB
weibofav_development['authentications'].find({:_id=>1751951491}).limit(-1).sort([[:_id, :asc]])
43 [0408 12:37:53(3092)DEBUG] after logger name: magazine