mark-gerarts / automapper-plus

An AutoMapper for PHP
MIT License
551 stars 30 forks source link

doctrine gets entities one by one #60

Closed PartosK closed 4 years ago

PartosK commented 4 years ago

I have entities that are related: building, house, properties

        $config
            ->registerMapping(DataCollectorBuilding::class, AggregateBuilding::class)
            ->forMember('houses', new MapTo(AggregateHouse::class));

        $config
            ->registerMapping(DataCollectorHouse::class, AggregateHouse::class)
            ->forMember('building', function(DataCollectorHouse $house) {
                return $house->getBuilding()->getId();
            })
            ->forMember('properties', new MapTo(AggregateProperty::class));
$config
            ->registerMapping(DataCollectorProperty::class, AggregateProperty::class)
            ->forMember('presetImage', function(DataCollectorProperty $property) {
                return !is_null($property->getPreset()) ? $property->getPreset()->getImage() : null;
            })
        ;

the property has a Preset and when I just ask for Building, the auto-mapper starts filling in related entities and the Preset fills in one by one

[2020-09-14 07:10:36] doctrine.DEBUG: SELECT t0.id AS id_1, t0.code AS code_2, t0.image AS image_3, t0.created_at AS created_at_4, t0.updated_at AS updated_at_5, t0.house_id AS house_id_6 FROM preset t0 WHERE t0.id = ? [1636] []
[2020-09-14 07:10:36] doctrine.DEBUG: SELECT t0.id AS id_1, t0.code AS code_2, t0.image AS image_3, t0.created_at AS created_at_4, t0.updated_at AS updated_at_5, t0.house_id AS house_id_6 FROM preset t0 WHERE t0.id = ? [1637] []
[2020-09-14 07:10:36] doctrine.DEBUG: SELECT t0.id AS id_1, t0.code AS code_2, t0.image AS image_3, t0.created_at AS created_at_4, t0.updated_at AS updated_at_5, t0.house_id AS house_id_6 FROM preset t0 WHERE t0.id = ? [1638] []
[2020-09-14 07:10:36] doctrine.DEBUG: SELECT t0.id AS id_1, t0.code AS code_2, t0.image AS image_3, t0.created_at AS created_at_4, t0.updated_at AS updated_at_5, t0.house_id AS house_id_6 FROM preset t0 WHERE t0.id = ? [1639] []
[2020-09-14 07:10:36] doctrine.DEBUG: SELECT t0.id AS id_1, t0.code AS code_2, t0.image AS image_3, t0.created_at AS created_at_4, t0.updated_at AS updated_at_5, t0.house_id AS house_id_6 FROM preset t0 WHERE t0.id = ? [1640] []

how can you get rid of this behavior?

PartosK commented 4 years ago

damn found the answer right there.....

fetch = "EAGER"