Chi
Chi

Reputation: 1410

typo3 extbase: is there a way to map exec_SELECTgetRows results to entities?

I have to make a rather complicated query to my database and at it seems that extbase queries cannot do what I need (for example, I need all categories with article-count > 0). So I created a query and execute it with exec_SELECTgetRows - now, is there a way to map the result back to entities?

I'd be thankful for any hints.

Upvotes: 4

Views: 671

Answers (1)

Viktor Livakivskyi
Viktor Livakivskyi

Reputation: 3228

You can achieve this by manually triggering PropertyMapper. Check the Flow docs about it. The concept is 1:1 same in ExtBase.

Some example code in your case may be following:

$objectStorage = $this->objectManager->get(ObjectStorage::class);
$propertyMapper = $this->objectManager->get(PropertyMapper::class);
$dataArray = $this->db->exec_SELECTgetRows(...);
foreach($dataArray as $data) {
    $dataObject = $propertyMapper->convert($data, \Your\Custom\Object::class);
    $objectStorage->attach($dataObject);
}

Upvotes: 6

Related Questions