dunglas / doctrine-json-odm

An object document mapper for Doctrine ORM using JSON types of modern RDBMS.
https://dunglas.fr
MIT License
580 stars 64 forks source link

Idea of using more property info for serializer #123

Open Hanmac opened 1 year ago

Hanmac commented 1 year ago

I don't know if this is an idea for this project or if it should be done for a different one

my idea is to use the property info for the serialized class:

/**
 * ORM Column("json_serial")
 */
property ?Block $content;

if the DoctrineType could access the info of the property somehow, then it could know into which classes it is doing to denormalize. Also it could get the serialize and deserialize context from the property and it wouldn't need extra stuff inside the json

while talking more with others, it seems it isn't as easy as i thought because the moment when doctrine is using the Type to get the data from the database, i can't access the property it is going into

so my idea probably need a different approach, so i need to get in between doctrine loading data from the database and it putting the data in the entities

bpolaszek commented 1 year ago

Hi @Hanmac,

Unfortunately Doctrine Types have no knowledge of the property context: types are just asked to convert a PHP value to a database one and backwards.

There's been some work done about being able to have a little less verbose JSONs, it's still in progress here.

Hanmac commented 1 year ago

Yeah that's what I got from reading the code too

Sadly not even the column options would help there because I thought I could inject the Outer Type into the options of the column, but that part isn't used either for this.

So for my idea I probably need to go deeper into the hydrator to see if I can get the data before it is loaded into the entity

Hanmac commented 1 year ago

my newest idea is to inject myself into hydrateColumnInfo and mess with the 'type' property in the _cache

then i could use a Decorated Doctrine Type object that wraps around the real Doctrine Type while still having the info of the column

but that's very hacky