我創(chuàng)建了一個類來更新購物車對象。當(dāng)我嘗試更新已存儲在數(shù)據(jù)庫中的對象時,出現(xiàn)錯誤The class "Doctrine\ODM\MongoDB\PersistentCollection" was not found in the chain configured namespaces App\Document"。此錯誤僅發(fā)生在購物車對象上(并且僅在對象更新期間。創(chuàng)建新對象運(yùn)行時沒有問題),盡管項(xiàng)目中存在類似的對象不會導(dǎo)致此類問題。除了這個錯誤,我還發(fā)現(xiàn)了幾個:僅當(dāng)您嘗試更新“EmbedMany”類型的字段時才會出現(xiàn)此錯誤。嘗試更新通過而沒有錯誤的所有其他字段。此外,對任何其他對象的任何操作都沒有問題。當(dāng)我嘗試使用 QueryBuilder 時,出現(xiàn)錯誤 Class 'Cart' does not exist用于更新購物車對象的類只是一組業(yè)務(wù)邏輯(經(jīng)過檢查,事實(shí)證明它不會以任何方式影響錯誤,所以我沒有展示邏輯)和標(biāo)準(zhǔn)對象保存使用:$cart = $this->documentManager->getRepository(Cart::class)->find('some_id');$cart->setProducts([/* CartItem[] */]);$this->documentManager->flush();我還附上了配置文件 ( config/packages/doctrine.yaml):doctrine_mongodb: auto_generate_proxy_classes: true auto_generate_hydrator_classes: true connections: default: server: '%env(resolve:MONGODB_URL)%' options: {} default_database: '%env(resolve:MONGODB_DB)%' document_managers: default: auto_mapping: true mappings: App: is_bundle: false type: annotation dir: '%kernel.project_dir%/src/Document' prefix: 'App\Document' alias: App可能是什么問題呢?
1 回答

楊魅力
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個贊
再次檢查每個邏輯階段返回的變量類型。從數(shù)據(jù)庫中檢索時,$cart->getProducts()
不知何故屬于 type [object] (Doctrine\\ODM\\MongoDB\\PersistentCollection: {})
,因此在更新購物車對象時未找到該類會發(fā)生錯誤。我還查看了Doctrine\Common\Collections\Collection
接口文檔,發(fā)現(xiàn)有一種toArray()
方法可以很好地PersistentCollection
轉(zhuǎn)換為[ CartItem[] ]
.
- 1 回答
- 0 關(guān)注
- 119 瀏覽
添加回答
舉報
0/150
提交
取消