Skip to content

Conversation

@soyuka
Copy link
Contributor

@soyuka soyuka commented Nov 16, 2025

Q A
Branch? 7.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #60610
License MIT

This allows to fix #60610 in a way that you can create the target in a transformer:

#[Map(target: TargetEntity::class, transform: GetTargetEntityReference::class)]
class SourceDto {
	public string $id;
}

class GetTargetEntityReference implements TransformCallableInterface
{
    public function __construct(
        private readonly EntityManager $em,
        private readonly ObjectMapperMetadataFactoryInterface $metadata
    ){
    }

    public function __invoke(mixed $value, object $source, ?object $target): mixed
    {

        $metadata = $this->metadata->create($value);
        \assert(count($metadata) === 1);
        return $this->entityManager->getReference($metadata[0]->target, $value->id);
    }
}

}

I consider this a bug fix as otherwise you're stuck with the Lazy Ghost. At least in a transform you can choose whether to map recursively or not (you can inject the ObjectMapper into a transformer to keep the same behavior).

@carsonbot carsonbot added this to the 7.4 milestone Nov 16, 2025
@soyuka soyuka force-pushed the fix/object-mapper-nested-objects branch from 442da33 to d42155a Compare November 16, 2025 21:07
@fabpot fabpot force-pushed the fix/object-mapper-nested-objects branch from 598abbe to 6dfe8b7 Compare November 20, 2025 07:05
@fabpot
Copy link
Member

fabpot commented Nov 20, 2025

Thank you @soyuka.

@fabpot fabpot merged commit 64d31ed into symfony:7.4 Nov 20, 2025
This was referenced Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants