You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea was to check if somehow is possible to make doctrine relation to be 'dynamic' and somehow to change relation on the flow.
How I approached and what I achieved:
I created some entities:
First hierarchy
abstractclassVehicle -> InheritanceType("SINGLE_TABLE")
classBusextendsVehicle
class CarextendsVehicle
class JeepextendsVehicle
class TruckextendsVehicle
Second hierarchy
abstractclassService -> InheritanceType("JOINED")
classCarwashextendsService
class ServiceStationextendsService
class TireShopextendsService
Okay, but now somehow I should change these relations that point to abstract classes with relation to concrete classes on the flow.
Because on deserialization process if you execute PUT/POST/PATCH request to Schedule API Point you will receive an error that the abstract class cannot be initialized.
And if execute GET request to get Schedule API Point serialization will not work correctly.
I noticed and the idea came to me if I somehow change the type of ApiPlatform\Core\Metadata\Property\PropertyMetadata maybe will work.
And I started.....
Okay, but now I somehow should understand what type to use for changes.
I did it in the following way:
On PUT/POST/PATCH operation I understand with what concrete PropertyMetadata's type to change abstract relation from the passed IRI:
POST /schedules HTTP/2
{
...
"vehicle": "/buses/1" -> from abstract class Vehicle to class Bus
"service": "/tire_shops/1" -> from abstract class Service to class TireShop
...
}
On the GET operation, I understand with what concrete class relation to change abstract PropertyMetadata's type from already populated object's property thanks to doctrine (because doctrine load it from the database and populate correctly):
GET /schedules/1 HTTP/2
/* @var $schedule Schedule */
/* @var $vehicle Bus */
$vehicle = $schedule->getVehicle()
...
from here change it -> from abstract class Vehicle to class Bus
Here is the implementation (there also are some functional tests) -> lubo13/api-platform
What do you think guys? If is it helpful I can move it in a bundle to be pluggable? Or maybe you have another idea?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I made one experiment to try one idea.
The idea was to check if somehow is possible to make doctrine relation to be 'dynamic' and somehow to change relation on the flow.
How I approached and what I achieved:
First hierarchy
Second hierarchy
and last entity
Note: The relations is point to abstract class.
Because on deserialization process if you execute PUT/POST/PATCH request to Schedule API Point you will receive an error that the abstract class cannot be initialized.
And if execute GET request to get Schedule API Point serialization will not work correctly.
I noticed and the idea came to me if I somehow change the type of ApiPlatform\Core\Metadata\Property\PropertyMetadata maybe will work.
And I started.....
Okay, but now I somehow should understand what type to use for changes.
I did it in the following way:
On PUT/POST/PATCH operation I understand with what concrete PropertyMetadata's type to change abstract relation from the passed IRI:
On the GET operation, I understand with what concrete class relation to change abstract PropertyMetadata's type from already populated object's property thanks to doctrine (because doctrine load it from the database and populate correctly):
Here is the implementation (there also are some functional tests) -> lubo13/api-platform
What do you think guys? If is it helpful I can move it in a bundle to be pluggable? Or maybe you have another idea?
Beta Was this translation helpful? Give feedback.
All reactions