Thanks to visit codestin.com
Credit goes to github.com

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).

@soyuka soyuka force-pushed the fix/object-mapper-nested-objects branch from 442da33 to d42155a Compare November 16, 2025 21:07
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.

3 participants