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
[Live Component] DoctrineObjectNormalizer is being used to normalize my non-Doctrine object #452
Comments
Hey @benr77, strange, the doctrine one should be skipped as the object is not managed. I'll look into this. I'm also questioning the priority. Currently, I don't think a custom doctrine entity normalizer can be used. |
#453 changes the priority from 100 to -100. I added a test that I think covers your scenario above (dto object with a normalizer) but couldn't recreate the error you received. |
My serializer is currently registered with a priority of -700, which IIRC is to ensure it is checked before But My form data class just looks like this: use Money\Money;
final class DefaultPriceData
{
public function __construct(
public string $itemType,
public Money $price
) {
}
} Thanks |
On further investigation, it turns out that This line returns It would seem that this is because I have a Doctrine embeddable defined to allow persisting Money objects to the database. <embeddable name="Money\Money">
<field name="amount" type="decimal" precision="0" scale="0" />
<field name="currency" type="currency"/>
</embeddable> So I'm guessing that the actual issue is simply that the |
Ahhh, now it makes sense! I'll work on a fix. |
Hmm, still can't reproduce the issue. In #453, I've added a test that demonstrates using an embeddable as an entity property but also a dto property. I've also confirmed that:
Returns |
I'm using doctrine/orm 2.13.1 Changing the priority for If I remove the code that registers the embeddable from my bundle, the Live Component starts working, but I run into an "Invalid Checksum" error instead. Not sure if this is related or not. Finally, the code that adds the embeddable does so using public function build(ContainerBuilder $container): void
{
parent::build($container);
$modelDir = realpath(__DIR__ . '/Doctrine/Mapping');
$mappings = [
$modelDir => 'Money',
];
if (class_exists(DoctrineOrmMappingsPass::class)) {
$container->addCompilerPass(
DoctrineOrmMappingsPass::createXmlMappingDriver(
$mappings,
['doctrine.orm.entity_manager'],
false
)
);
}
} Not sure if any of this is helpful sorry. |
Finally solved! Was a tricky one: when embeddables are mapped using annotations, |
You sir, are a legend. Isn't this a Doctrine bug then? |
Found a bit of context. I actually solved this exact thing in zenstruck/foundry earlier this year! Refs:
In short, it looks like it is a bug but fixing it causes other problems so they're leaving alone for now. Sounds like it will all be refactored/fixed in ORM 3.0. |
Using v2.3 of the Live Component.
I'm using a DTO as a data class with a form in a live component. It's working OK with scalar values in the DTO.
However, when I try and use
Money/Money
object as one of the form data properties, it borks with:Looking at the
DoctrineObjectNormalizer
I see it is given a priority of 100, making it kick in way before my custom Money normalizer which is already registered with the serializer.Why is the
DoctrineObjectNormalizer
given such a high priority, and why is it trying to normalize my non-Doctrine object?What would be the best way to get around this?
Thank you.
The text was updated successfully, but these errors were encountered: