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

leebo-github · December 18, 2018 · 5555 hits

模型

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 closed this topic. 18 Dec 12:35
leebo-github reopened this topic. 18 Dec 12:35
You need to Sign in before reply, if you don't have an account, please Sign up first.