Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withoutPersisting schedules for insert in Doctrine UnitOfWork #816

Open
tandev opened this issue Feb 14, 2025 · 3 comments · May be fixed by #817
Open

withoutPersisting schedules for insert in Doctrine UnitOfWork #816

tandev opened this issue Feb 14, 2025 · 3 comments · May be fixed by #817
Labels
bug Something isn't working

Comments

@tandev
Copy link

tandev commented Feb 14, 2025

Hi, im unsureif it was introduced in the latest 2.3.2 version, but it seems like persistance is inconsistently handled.

Factories that have persistence disabled, are still scheduling for insert for children.

 $contact = static::contactFactory()->withoutPersisting()->create([
            'tags' => static::tagFactory()::new()->many(3),
            'category' => static::categoryFactory(),
        ]);

This can be observed in the \Zenstruck\Foundry\Tests\Integration\ORM\EntityRelationship\EntityFactoryRelationshipTestCase::disabling_persistence_cascades_to_children test by checking the UnitOfWork insertions

Image

Unless withoutPersisting is not the same meaning as in doctrine, let me know if i misunderstood something here

        foreach ($contact->getTags() as $tag) {
            $this->assertNull($tag->id);
++            static::assertFalse(Configuration::instance()->persistence()->isPersisted($tag));
        }

i tested if i can enhance the test by a isPersisted check, but this is always returning false despite being scheduled for insert by doctrine

@tandev tandev changed the title withoutPersisting schedules for insert withoutPersisting schedules for insert in Doctrine UnitOfWork Feb 14, 2025
@nikophil
Copy link
Member

Yeah, we should add a flush() in the test where you took the example to assert nothing is passed to the UoW.

I'll fix that in few days as well

@nikophil nikophil added the bug Something isn't working label Feb 16, 2025
@nikophil nikophil linked a pull request Feb 16, 2025 that will close this issue
@nikophil
Copy link
Member

nikophil commented Feb 16, 2025

@tandev would you mind to test if #817 fixes the problem in your project? It actually fixes it in our test

@tandev
Copy link
Author

tandev commented Feb 17, 2025

Hi. looks good, we had setup some entities withoutPersisting() for reference and those get not tried to be persisted anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants