Get the object of Child type instead of parent from MongoDB Get the object of Child type instead of parent from MongoDB symfony symfony

Get the object of Child type instead of parent from MongoDB


If I understand your issue correctly, you need PHP's built-in get_class() or get_called_class() functions.

Note : Objects themselves shouldn't forget which class they belong to, even if they are being returned by a function/method that only "knows" they are returning some instance of the superclass or one of its subclasses. So you should always be able to query which class an instance belongs to, via the get_class($instance) function.


I figured out that if I save an entity as a base class object than it will returns the object of base class and so in the above example if I need to get the desired results, I have to save it appropriately.