foundry icon indicating copy to clipboard operation
foundry copied to clipboard

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

Open rimas-kudelis opened this issue 1 year ago • 2 comments

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 avatar May 22 '24 08:05 rimas-kudelis

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;
            }

rimas-kudelis avatar May 22 '24 10:05 rimas-kudelis

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

nikophil avatar Jun 20 '24 15:06 nikophil