MongoDB mongoid model update 时会查询 has_one 关联属性

leebo-github · 2018年12月18日 · 5555 次阅读

模型

User name:string
Profile age:integer

User has_one :profile
Profile belongs_to :user

User.first.update(name: 'xxxx')

会触发

D, [2018-12-18T12:33:25.612410 #31808] DEBUG -- : MONGODB | localhost:27017 | m_development.find | STARTED | {"find"=>"users", "filter"=>{}, "sort"=>{"_id"=>1}, "limit"=>1, "singleBatch"=>true, "lsid"=>{"id"=><BSON::Binary:0x70240119236940 type=uuid data=0x72ff27da5b0142c9...>}}
D, [2018-12-18T12:33:25.614074 #31808] DEBUG -- : MONGODB | localhost:27017 | m_development.find | SUCCEEDED | 0.001s
D, [2018-12-18T12:33:25.624208 #31808] DEBUG -- : MONGODB | localhost:27017 | m_development.find | STARTED | {"find"=>"profiles", "filter"=>{"user_id"=>BSON::ObjectId('5c17c80178d1e2347dca77b2')}, "limit"=>1, "singleBatch"=>true, "lsid"=>{"id"=><BSON::Binary:0x70240119236940 type=uuid data=0x72ff27da5b0142c9...>}}
D, [2018-12-18T12:33:25.624993 #31808] DEBUG -- : MONGODB | localhost:27017 | m_development.find | SUCCEEDED | 0.001s
D, [2018-12-18T12:33:25.626517 #31808] DEBUG -- : MONGODB | localhost:27017 | m_development.update | STARTED | {"update"=>"users", "ordered"=>true, "lsid"=>{"id"=><BSON::Binary:0x70240119236940 type=uuid data=0x72ff27da5b0142c9...>}, "updates"=>[{"q"=>{"_id"=>BSON::ObjectId('5c17c80178d1e2347dca77b2')}, "u"=>{"$set"=>{"name"=>"xxxx"}}, "multi"=>false, "upsert"...
D, [2018-12-18T12:33:25.627230 #31808] DEBUG -- : MONGODB | localhost:27017 | m_development.update | SUCCEEDED | 0.001s

我试了用 ActiveRecord 不会有这样的问题 这块有点搞不懂 为什么要去查询 profiles 呢

leebo-github 关闭了讨论。 12月18日 12:35
leebo-github 重新开启了讨论。 12月18日 12:35
需要 登录 后方可回复, 如果你还没有账号请 注册新账号