Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to select as an object that entity with no relation in DQL?
    text
    copied!<p>For example, there is a DQL that get some articles.</p> <pre><code>$query = $this-&gt;getEntityManager()-&gt;createQuery(' SELECT a, t, u FROM MyArticleBundle:Article a LEFT JOIN a.tags t LEFT JOIN a.author u WHERE a.id IN (1,2,3) ORDER BY a.id DESC '); </code></pre> <p>I use this data as an object.</p> <p>Such as:</p> <pre><code>$article-&gt;getId(); $article-&gt;getAuthor(); etc... </code></pre> <p>But, it is occurred that needs to be joined with no relation data to this data.<br> For example, I get comments with data.</p> <pre><code>$query = $this-&gt;getEntityManager()-&gt;createQuery(' SELECT a, t, u, c FROM MyArticleBundle:Article a LEFT JOIN a.tags t LEFT JOIN a.author u LEFT JOIN MyCommentBundle:Comment c WITH c.chain_id = a.id AND c.app = :appName WHERE a.id IN (1,2,3) ORDER BY a.id DESC ') -&gt;setParameter('appName', 'article'); </code></pre> <p>It may be possible to get the data.<br> But, program (such a '$article->getId();') does not work.</p> <blockquote> <p>FatalErrorException: Error: Call to a member function getId() on a non-object</p> </blockquote> <p>A problem point is 'c' at 'SELECT a, t, u, c '.<br> Is it possible to select as an object that comments with no relation in DQL?<br> Should I correct the program.</p> <hr> <p><em><strong>EDIT:</em></strong></p> <p>DB(Table) relationships are not.<br> I wouldn't like to relate comment table to article table because I want to manage it separately from other app.<br> However, the connected ID exists.<br> It is 'chain_id' and 'app' at the case of above code.</p> <p>So I could get related comments of article.<br> Problem is that fetching data is array.</p> <p>What I mean is, I would like to get comments data as an child node of article data object at the case of above code.<br> I want to access the data like <code>$article-&gt;comments</code>.</p> <p>This is the code that that I've seen before.</p> <pre><code>$this-&gt;bind( array('SomeLog as SomeLogs', array( 'local' =&gt; 'id', 'foreign' =&gt; 'record_id', )), Doctrine_Relation::MANY // means hasMany ); </code></pre> <p>I think this code is for doctrine version 1.<br> I think that it is used when combining to force the table with no relation.</p> <p>I hope that perhaps there is another way in doctrine version 2.</p>
 

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