Skip to main content
added 7 characters in body
Source Link
Arthur
  • 1.4k
  • 1
  • 18
  • 35

So i found the problem! Instead of JOIN i used LEFT JOIN:

$query = $em->createQuery("SELECT p, rl FROM <Bundle>:BlogPosts p LEFT JOIN p.replies rl WHERE p.user = 1");
$posts = $query->getResult(); // ReturnsNow emptyit arrayworks like a charm!

So now MySQL joins the result to the blog posts! When using a simple JOIN, it tries to join the posts to the replies, in witch case the result will be empty if the post doesn't have any!

So i found the problem! Instead of JOIN i used LEFT JOIN:

$query = $em->createQuery("SELECT p, rl FROM <Bundle>:BlogPosts p LEFT JOIN p.replies rl WHERE p.user = 1");
$posts = $query->getResult(); // Returns empty array

So now MySQL joins the result to the blog posts! When using a simple JOIN, it tries to join the posts to the replies, in witch case the result will be empty if the post doesn't have any!

So i found the problem! Instead of JOIN i used LEFT JOIN:

$query = $em->createQuery("SELECT p, rl FROM <Bundle>:BlogPosts p LEFT JOIN p.replies rl WHERE p.user = 1");
$posts = $query->getResult(); // Now it works like a charm!

So now MySQL joins the result to the blog posts! When using a simple JOIN, it tries to join the posts to the replies, in witch case the result will be empty if the post doesn't have any!

Source Link
Arthur
  • 1.4k
  • 1
  • 18
  • 35

So i found the problem! Instead of JOIN i used LEFT JOIN:

$query = $em->createQuery("SELECT p, rl FROM <Bundle>:BlogPosts p LEFT JOIN p.replies rl WHERE p.user = 1");
$posts = $query->getResult(); // Returns empty array

So now MySQL joins the result to the blog posts! When using a simple JOIN, it tries to join the posts to the replies, in witch case the result will be empty if the post doesn't have any!