Document is insert and then updated during one flush operation
oleg-andreyev opened this issue · 4 comments
Bug Report
Similar as #1058
Q | A |
---|---|
BC Break | no |
Version | 2.7.x |
Summary
While working on doctrine-extensions/DoctrineExtensions#2784 noticed that calling scheduleForUpdate
after insert, won't allow to change scheduledDocumentUpdates
and perform update because entity/document could is in scheduledDocumentInsertions
Current behavior
Cannot update after insert.
Expected behavior
Would great to backport scheduleExtraUpdate
from ORM and allow this extra updates.
@oleg-andreyev the PR you're linking to is too big for me to go through it. What exactly would be the use case for scheduleExtraUpdate
in ODM? IIRC ORM's main use case was setting an auto-generated ID to a previously inserted document in a relation, and that's not needed in ODM.
@malarzm there is a tree logic called materialized path
, which also requires ID to be generated (alternative to tree traversal)
In a default setting document's identifier is known upfront, before inserting to the database. Those identifiers can be gathered before inserting all documents, so why should we complicate ODM's logic with scheduleExtraUpdate
?
@malarzm could you please point where this lib. generate ID upfron before insert?
if id
is marked as \Doctrine\ODM\MongoDB\Mapping\Annotations\Id
(strategy: auto),
I see that it's using native insert https://www.php.net/manual/en/mongodb-driver-bulkwrite.insert.php
and it see said:
Returns the _id of the inserted document. If the document did not have an _id, the MongoDB\BSON\ObjectId generated for the insert will be returned.
UPD: nevermind, found it.
Issue "probably" is more retailed to abstraction of DoctrineExtensions, in case of ODM id is know because generate at application side, but in case of e.g. MySQL auto_increment strategy thus lib is "performing" post-insert updates this is where "scheduleExtraUpdate" could help.