Note that there are some explanatory texts on larger screens.

plurals
  1. POLeft Join with Where clause returns empty result
    primarykey
    data
    text
    <p>I have got a <code>post</code> table and it's schema is like this:</p> <pre><code>CREATE TABLE IF NOT EXISTS `post` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `user_id` bigint(20) DEFAULT NULL, `site_id` bigint(20) DEFAULT NULL, `parent_id` bigint(20) DEFAULT NULL, `title` longtext COLLATE utf8_turkish_ci NOT NULL, `status` varchar(20) COLLATE utf8_turkish_ci NOT NULL, PRIMARY KEY (`id`), KEY `IDX_5A8A6C8DA76ED395` (`user_id`), KEY `IDX_5A8A6C8DF6BD1646` (`site_id`), KEY `IDX_5A8A6C8D727ACA70` (`parent_id`), ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci AUTO_INCREMENT=16620 ; </code></pre> <p>I'm using this DQL to fetch a post and it's children:</p> <pre><code>$post = $this-&gt;_diContainer-&gt;wordy_app_doctrine-&gt;fetch( "SELECT p,c FROM Wordy\Entity\Post p LEFT JOIN p.children c WHERE p.site = :site AND p.id = :id AND p.language = :language AND p.status != 'trashed' AND c.status != 'trashed' ORDER BY c.title", array( 'params' =&gt; array( 'id' =&gt; $id, 'site' =&gt; $this-&gt;_currentSite['id'], 'language' =&gt; $this-&gt;_currentLanguage-&gt;code, ) ) ); </code></pre> <p>What i'm trying to do is: Fetch a post and all of it's children. The criteria is, don't include trashed posts or trashed children.</p> <p>But when i run this query with a post which doesn't even have children, the returned result set is empty.</p> <p>When i remove the <code>c.status != 'trashed'</code> part from query, everything works fine but i will get trashed posts too.</p> <p>Thanks, in advance.</p> <p>edit: here is the SQL output of given DQL:</p> <pre><code>SELECT p0_.id AS id0, p0_.title AS title5, p0_.status AS status8, p0_.parent_id AS parent_id9, p1_.id AS id15, p1_.title AS title20, p1_.status AS status23, p1_.parent_id AS parent_id24 FROM post p0_ LEFT JOIN post p1_ ON p0_.id = p1_.parent_id WHERE p0_.site_id = ? AND p0_.id = ? AND p0_.language = ? AND p0_.status &lt;&gt; 'trashed' ORDER BY p1_.title ASC </code></pre>
    singulars
    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