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

[Question] How to refer an object from native Doctrine fixtures? #1237

Open
TomasVotruba opened this issue Jan 12, 2025 · 4 comments
Open

[Question] How to refer an object from native Doctrine fixtures? #1237

TomasVotruba opened this issue Jan 12, 2025 · 4 comments
Labels

Comments

@TomasVotruba
Copy link

TomasVotruba commented Jan 12, 2025

Hi, I'm doing a huge migration of old forked Alice/Fixture/Hautelook/Faker packages (total mess).

We use native Doctrine PHP fixtures, where we set a reference:

$this->addReference('pretty-car', $car);

We use these object further in Alice fixture, where we fetch them from database (not sure why).

I want use reference in Alice to avoid calling database, as we normally do:

App\Entity\User:
    tom:
        car: "@pretty-car"

But this doesn't work. Any way how to make it happen?

I've noticed there is a \Doctrine\Common\DataFixtures\ReferenceRepository that collects all references, but not sure how/where to inject it into Alice, so Alice can fetch referenced objects from there.


Thank you 🙏

@TomasVotruba TomasVotruba changed the title [Questoin] How to get reference object from native Doctrine fixtures? [Questoin] How refer an object from native Doctrine fixtures? Jan 12, 2025
@TomasVotruba TomasVotruba changed the title [Questoin] How refer an object from native Doctrine fixtures? [Question] How refer an object from native Doctrine fixtures? Jan 12, 2025
@TomasVotruba TomasVotruba changed the title [Question] How refer an object from native Doctrine fixtures? [Question] How to refer an object from native Doctrine fixtures? Jan 12, 2025
@theofidry
Copy link
Member

Hi!

The answer depends on a bit on how you are calling Alice, but given your issue I assume you are calling directly a loader. With AliceDataFixtures, there is a objects parameter for Fidry\AliceDataFixtures\LoaderInterface::load().

@TomasVotruba
Copy link
Author

TomasVotruba commented Jan 12, 2025

Thanks for quick answer. I've tried to bump to AliceDataFixtures but our deps are too old. I'll switch once we're there.

How can I emulate similar behavior in our old nelmio/alice? Link to code could be enough.

@theofidry
Copy link
Member

So... I'll have to assume we are talking of Alice2 then? Probably overriding https://github.com/nelmio/alice/blob/2.x/src/Nelmio/Alice/Fixtures/Loader.php#L268 or something like that... I'm not super familiar with the v2 codebase, it's a very old one which I barely touched (mostly adding tests when designing v3...)

in v3 the NelmioAlice loader should allow the same, but note that it does not persist objects, so I'm not sure how it's done in your codebase...

@TomasVotruba
Copy link
Author

Thanks 👍

It's a fork of fork of 2.3.x to be exact.
I think I know how to override the Loader. The only thing I miss the service/place to fetch existing Doctrine PHP native fixture references from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants