Skip to content

v2.10.3

Choose a tag to compare

@nikophil nikophil released this 20 Jul 16:59
· 70 commits to 2.x since this release
Immutable release. Only release title and notes can be modified.

Minor BC break: state computed by PrePersist listeners is no longer visible from hooks with default priority

Previously, objects created by nested factories were passed to $em->persist() during the
creation of the object graph. Their PrePersist listeners could therefore observe — and even
corrupt (#1115) — a half-built graph, but it also meant their side effects (e.g. a field computed
in the listener) were already applied when your afterInstantiate() hooks ran.

Persistence is now deferred until the whole object graph is instantiated and wired, so hooks with
default priority run before any lifecycle event has been triggered. If one of your hooks reads
state computed by a PrePersist listener, give it a priority lower than
PersistentObjectFactory::PRIORITY_SCHEDULE_FOR_INSERT:

use Zenstruck\Foundry\Persistence\PersistentObjectFactory;

OrderItemFactory::new()
    ->afterInstantiate(function(OrderItem $item): void {
        // computed in Order's PrePersist listener — visible here, on a fully wired graph
        $item->setProcess($item->getOrder()->getProcess());
    }, priority: PersistentObjectFactory::PRIORITY_SCHEDULE_FOR_INSERT - 1);


c851f6d fix: defer `$em->persist()` until the object graph is wired + natural accessor directionality (#1134) by @nikophil

[Full Change List](https://github.com/zenstruck/foundry/compare/v2.10.2...v2.10.3)