Hi,

I'm facing a small trouble with SF2 and doctrine, the former calling 
Collection->clear method when submitting empty multiple entities forms, the 
latter taking a snapshot when the clear method is called on 
PersistentCollections.
Since I want to perform actions when there are modifications on some 
entities, I need to know the changes implied by the collection clear calls.

So I tried something, which is probably a non-sense doctrine wise and prone 
to errors, by detaching the collection owner entity, fetching it again from 
db, comparing collections and merging the detached entity back in UoW in 
the onFlush event. Everything seems fine till UoW tries to persist the 
entity. It could be summarized as :

$eventManager->addEventListener(Events::onFlush, function(OnFlushEventArgs 
$args) {
    $em = $args->getEntityManager();
    $uow = $em->getUnitOfWork();

    foreach ($uow->getScheduledCollectionDeletions() as $collection) {
        if (! $collection->count()) {
            $owner = $collection->getOwner();
            $uow->detach($owner);
            $refOwner = $em->find(get_class($owner), $owner->getId());
            // compare $collection and $refOwner's collection
            $uow->merge($owner);
        }
    }
});

I know this is / seems to be tricky, confirmed by the PDO Error Invalid 
parameter number : no parameters were bound, but I must find a trick anyway.

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to