Возвращать результаты соединения «один ко многим» в виде массивов в объекте ⇐ Php
Возвращать результаты соединения «один ко многим» в виде массивов в объекте
I have a table for posts and another table with reply posts. I have a One (post) to Many (reply posts) relation mapped in doctrine correctly. I can join the two and get what i'd expect, an array of arrays for each reply, but the content from the original post is the same. Is it possible to return a single array/object for each post with the reply contents in an array?
Here's what i get now (as expected):
array (size=2) 0 => array (size=2) 'content' => string 'Test homework post' (length=18) 'replyContent' => string 'this is a reply' (length=15) 1 => array (size=2) 'content' => string 'Test homework post' (length=18) 'replyContent' => string 'second reply' (length=12) I want something like this:
array (size=1) 0 => array (size=2) 'content' => string 'Test homework post' (length=18) 'replyContent' => array (size = 2) 0 => 'replyContent' => string 'this is a reply' (length=15) 1 => 'replyContent' => string 'second reply' (length=12) I've done my best researching, but have only come across results regarding returning arrays instead of objects. Maybe it isn't possible, but I thought it might be considering one-to-many relation mapping in the php classes define:
$this->[name for protected variable] = new ArrayCollection(); Thanks so much for any help!
Edit: This is my doctrine query:
SELECT homeworkPost.content, homeworkPostReplies.content AS replyContent FROM AcmeMainBundle:HomeworkPost homeworkPost LEFT JOIN homeworkPost.homeworkPostReplies homeworkPostReplies WHERE homeworkPost.course = :course
Источник: https://stackoverflow.com/questions/156 ... -an-object
I have a table for posts and another table with reply posts. I have a One (post) to Many (reply posts) relation mapped in doctrine correctly. I can join the two and get what i'd expect, an array of arrays for each reply, but the content from the original post is the same. Is it possible to return a single array/object for each post with the reply contents in an array?
Here's what i get now (as expected):
array (size=2) 0 => array (size=2) 'content' => string 'Test homework post' (length=18) 'replyContent' => string 'this is a reply' (length=15) 1 => array (size=2) 'content' => string 'Test homework post' (length=18) 'replyContent' => string 'second reply' (length=12) I want something like this:
array (size=1) 0 => array (size=2) 'content' => string 'Test homework post' (length=18) 'replyContent' => array (size = 2) 0 => 'replyContent' => string 'this is a reply' (length=15) 1 => 'replyContent' => string 'second reply' (length=12) I've done my best researching, but have only come across results regarding returning arrays instead of objects. Maybe it isn't possible, but I thought it might be considering one-to-many relation mapping in the php classes define:
$this->[name for protected variable] = new ArrayCollection(); Thanks so much for any help!
Edit: This is my doctrine query:
SELECT homeworkPost.content, homeworkPostReplies.content AS replyContent FROM AcmeMainBundle:HomeworkPost homeworkPost LEFT JOIN homeworkPost.homeworkPostReplies homeworkPostReplies WHERE homeworkPost.course = :course
Источник: https://stackoverflow.com/questions/156 ... -an-object
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение