4

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.

Chi
  • 1,320
  • 1
  • 14
  • 48
  • 2
    Maybe you already considered this, but wouldn't ```$query->statement``` be sufficient for your needs? – lorenz Dec 27 '15 at 12:24

1 Answers1

6

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);
}
Viktor Livakivskyi
  • 3,178
  • 1
  • 21
  • 33