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
While using the ResultSetMapping object to hydrate a doctrine-managed entity from a native SQL request I could not hydrate parameters that do not correspond to a db column.
the SQL query counts the total number of pages by book. I don't want to add a nb_pages column in my book table.
the entity :
#[ORM\Entity(repositoryClass: BookRepository::class)]
classBook {
#[ORM\Column(length: 255)]
publicstring$title = ''; // this I can hydrate as expectedpublic ?int$nbPages = null; // this doesn't seem to be hydratable with ResultSetMapping
[...]
}
the mapping :
$rsm = newResultSetMapping();
$rsm->addEntityResult(Book::class, 'project')
->addMetaResult('project', 'project_id', 'id', true)
->addFieldResult('project', 'project_id', 'id')
->addFieldResult('project', 'project_created_at', 'createdAt')
->addFieldResult('project', 'project_updated_at', 'updatedAt')
->addFieldResult('project', 'project_title', 'title');
$rsm->addJoinedEntityResult(Chapter::class, 'c', 'project', 'chapters')
->addMetaResult('c', 'chapter_id', 'id', true)
->addFieldResult('c', 'chapter_id', 'id')
->addFieldResult('c', 'chapter_title', 'title')
->addFieldResult('c', 'chapter_position', 'position')
->addFieldResult('c', 'chapter_created_at', 'createdAt')
->addFieldResult('c', 'chapter_updated_at', 'updatedAt');
$rsm->addJoinedEntityResult(Page::class, 'p', 'c', 'pages')
->addFieldResult('p', 'page_id', 'id')
->addFieldResult('p', 'page_created_at', 'createdAt')
->addFieldResult('p', 'page_updated_at', 'updatedAt')
->addFieldResult('p', 'page_position', 'position')
->addFieldResult('p', 'page_published_at', 'publishedAt')
->addFieldResult('p', 'page_title', 'title');
// I tried to hydrate it as if It were a DTO as explained in the documentation but this did not work :$rms->addScalarResult('total_pages', 'nbPages');
$rsm->newObjectMappings['nbPages'] = [
'className' => Book::class,
'objIndex' => 0,
'argIndex' => 'nbPages'
];
The text was updated successfully, but these errors were encountered:
Feature Request
Summary
While using the ResultSetMapping object to hydrate a doctrine-managed entity from a native SQL request I could not hydrate parameters that do not correspond to a db column.
the SQL query counts the total number of pages by book. I don't want to add a nb_pages column in my book table.
the entity :
the mapping :
The text was updated successfully, but these errors were encountered: