Symfony/Doctrine: How does addJoinedEntityResult work for a one-to-many relationship? -
i have following problem. guess misunderstanding. after googling hours without finding solution post here.
i have native query in doctrine:
$rsm = new resultsetmapping; $rsm->addentityresult('acme\commentbundle\entity\comment', 'c'); $rsm->addfieldresult('c', 'comment_id', 'id'); $rsm->addfieldresult('c', 'slug', 'slug'); $rsm->addfieldresult('c', 'comment', 'comment'); $rsm->addfieldresult('c', 'created', 'created'); $rsm->addjoinedentityresult('acme\accountbundle\entity\worker', 'w', 'c', 'komments'); $rsm->addfieldresult('w', 'worker_id', 'id'); $rsm->addfieldresult('w', 'worker_name', 'name'); $rsm->addjoinedentityresult('acme\commentbundle\entity\document', 'd', 'c', 'documents'); $rsm->addfieldresult('d', 'document_id', 'id'); $rsm->addfieldresult('d', 'document_name', 'name'); return $this->getentitymanager() ->createnativequery('select t.id, c.id comment_id, c.slug, c.created, c.comment, c.worker_id comment_worker_id, c.created comment_created, d.id document_id, d.name document_name, w.id worker_id, w.name worker_name comment_thread t inner join project p on p.comment_thread_id = t.id left join comment c on t.id = c.thread_id inner join worker w on c.worker_id = w.id left join comment_document d on c.id = d.comment_id p.id = :project_id order c.created asc', $rsm) ->setparameter('project_id', $
unfortunately first addjoinedentityresult (worker) not working. if remove remaining addjoinedentityresult (document) perfect.
i guess because document linked comment. comment "parent" of document. in case of worker vice versa: comment "child" of worker , not "parent" document.
in other words: - worker can have multiple comments - comment can have multiple documents
my result set should have comment base, (one) worker , (0 .. n) documents associated.
but how set relationships in doctrine result mapping?
any appreciated :-)
nicki
my suggestion mapper rewrites "name" field when attach second entity. had same situation , fixed renaming field in table , in entity mapping , in entity class different entities/tables don't have same name properties/columns.
Comments
Post a Comment