postgresql-for-doctrine icon indicating copy to clipboard operation
postgresql-for-doctrine copied to clipboard

Jsonb type limited convert

Open halfik opened this issue 1 year ago • 4 comments

JsonB type has now limitation on convertToPhpValue function. You can't convert to some custom php classes now like this:

public function convertToPHPValue($value, AbstractPlatform $platform): Currency

Any reason behind limiting convert to only simple php types?

halfik avatar Oct 17 '23 09:10 halfik

I don't fully understand your idea. Can you please elaborate with more details?

martin-georgiev avatar Jan 11 '24 23:01 martin-georgiev

https://github.com/martin-georgiev/postgresql-for-doctrine/blob/main/src/MartinGeorgiev/Doctrine/DBAL/Types/Jsonb.php

You limited types int this when it convertio into. It can convert any object itno jsonb, but you won't be able to recreate same object from jsob.

So u can conber instance of my CustomClass but i can't get it back since im limited to simple types only.

halfik avatar Jan 12 '24 08:01 halfik

Can you add some code samples, please? The phpdoc for Jsonb clearly says that only array|bool|float|int|string|null data types are supported.

martin-georgiev avatar Jan 13 '24 12:01 martin-georgiev

Yes and that is an issue. You can conver instance of CustomClass into jsonb on db, but u cant conver from db to CustomClass bc you can get only array|bool|float|int|string|null

convertToDatabaseValue allows to convert any object u want into db string convertToPHPValue won't allow to recreate it

And its a big issue in DDD aproach where u have lot of domain defined custom objects you want to store as jsonb.

halfik avatar Jan 17 '24 07:01 halfik