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

Using story pools without persisting #573

Open
Brewal opened this issue Mar 26, 2024 · 0 comments · May be fixed by #580
Open

Using story pools without persisting #573

Brewal opened this issue Mar 26, 2024 · 0 comments · May be fixed by #580

Comments

@Brewal
Copy link

Brewal commented Mar 26, 2024

I'm using foundry without doctrine and manually save my objects with this function in my factories :

protected function initialize(): self
    {
        return $this->withoutPersisting()
            ->afterInstantiate(
                fn (Establishment $establishment) => $this->repository->save($establishment),
            );
    }

I'm facing an issue while using stories and pools.

If I call $this->addToPool() inside a story, I get the following error :

RuntimeException : Should not get doctrine's object manager when persist is disabled.

What I understood is that I wouldn't be able to use pools because of the normalizeObject private method of Story :

        // ensure proxies are persisted
        if (!$object->isPersisted()) {
            $object->save();
        }

Is there a workaround for this use case ?

Thanks to this : #488 we can globally disable persist. Would it make sense to check for this configuration in the Story ?

jrushlow added a commit to jrushlow/foundry that referenced this issue Mar 30, 2024
a wip to fix using stories with objects that can't be persisted

This is intended to be legacy code that shouldn't be merged into 2.x.

fixes: zenstruck#573
jrushlow added a commit to jrushlow/foundry that referenced this issue Mar 30, 2024
a wip to fix using stories with objects that can't be persisted

This is intended to be legacy code that shouldn't be merged / released in 2.x.

fixes: zenstruck#573
jrushlow added a commit to jrushlow/foundry that referenced this issue Mar 30, 2024
a wip to fix using stories with objects that can't be persisted

This is intended to be legacy code that shouldn't be merged / released in 2.x.

fixes: zenstruck#573
jrushlow added a commit to jrushlow/foundry that referenced this issue Mar 30, 2024
a wip to fix using stories with objects that can't be persisted

This is intended to be legacy code that shouldn't be merged / released in 2.x.

fixes: zenstruck#573
@jrushlow jrushlow linked a pull request Mar 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant