zenstruck / foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html
MIT License
607 stars 62 forks source link

`make:factory` fails when there is more than one level of embedded classes #608

Open rimas-kudelis opened 1 month ago

rimas-kudelis commented 1 month ago

When attempting to generate a factory for a class that has a protected property of Money\Money type, I get the following error:

In LegacyORMDefaultPropertiesGuesser.php line 73:

  Property App\Entity\MyEntity::$price.currency does not exist

I'm using Foundry version 1.37.0.

rimas-kudelis commented 1 month ago

This happens because $metadata->embeddedClasses contains a list that is too comprehensive (it lists not only child objects, but also deeper descendants).

A seemingly working fix is to add a simple check before the faulty line:

            if (str_contains($fieldName, '.')) {
                continue;
            }
nikophil commented 6 days ago

Hi @rimas-kudelis

would you mind adding a little bit more context, please? as least, how would look the minimal entity that makes the command break.

Thanks