Note that there are some explanatory texts on larger screens.

plurals
  1. POreturn One-To-Many join results as arrays in an object
    primarykey
    data
    text
    <p>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?</p> <p>Here's what i get now (as expected):</p> <pre><code>array (size=2) 0 =&gt; array (size=2) 'content' =&gt; string 'Test homework post' (length=18) 'replyContent' =&gt; string 'this is a reply' (length=15) 1 =&gt; array (size=2) 'content' =&gt; string 'Test homework post' (length=18) 'replyContent' =&gt; string 'second reply' (length=12) </code></pre> <p>I want something like this:</p> <pre><code>array (size=1) 0 =&gt; array (size=2) 'content' =&gt; string 'Test homework post' (length=18) 'replyContent' =&gt; array (size = 2) 0 =&gt; 'replyContent' =&gt; string 'this is a reply' (length=15) 1 =&gt; 'replyContent' =&gt; string 'second reply' (length=12) </code></pre> <p>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:</p> <pre><code>$this-&gt;[name for protected variable] = new ArrayCollection(); </code></pre> <p>Thanks so much for any help!</p> <p>Edit: This is my doctrine query:</p> <pre><code> SELECT homeworkPost.content, homeworkPostReplies.content AS replyContent FROM AcmeMainBundle:HomeworkPost homeworkPost LEFT JOIN homeworkPost.homeworkPostReplies homeworkPostReplies WHERE homeworkPost.course = :course </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload