Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7088105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:45:24+00:00 2026-05-28T07:45:24+00:00

I try to execute this query in my CompanyRepository $qb = $this->_em->createQueryBuilder(); $qb->select(array(‘c’, ‘ld’))

  • 0

I try to execute this query in my CompanyRepository

$qb = $this->_em->createQueryBuilder();
$qb->select(array('c', 'ld'))
        ->from('Model\Entity\Company', 'c')
        ->leftJoin('c.legaldetails', 'ld', \Doctrine\ORM\Query\Expr\Join::ON, 'c.companyid=ld.companyid');

$query = $qb->getQuery();
echo($query->getSQL());

When I try to do it I having error:

Fatal error: Uncaught exception ‘Doctrine\ORM\Query\QueryException’ with message ‘[Syntax Error] line 0, col 69: Error: Expected end of string, got ‘ON” in /home/raccoon/web/freetopay.dev/www/class/new/library/Doctrine/ORM/Query/QueryException.php on line 42

These are my models:

<?php    
namespace Model\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Company
 *
 * @ORM\Table(name="Company")
 * @ORM\Entity(repositoryClass="\Model\Repository\CompanyRepository")
 */
class Company
{
/**
 * @var integer $companyid
 *
 * @ORM\Column(name="CompanyID", type="integer", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $companyid;

/**
 * @var \Model\Entity\LegalDetails $legaldetails
 *
 * @ORM\OneToOne(targetEntity="\Model\Entity\Legaldetails", mappedBy="companyid")
 */
private $legaldetails;

//other fields

public function __construct()
{
    $this->legaldetails = new ArrayCollection();
}    

//setters and getters

and legaldetails entity:

<?php
namespace Model\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Legaldetails
 *
 * @ORM\Table(name="LegalDetails")
 * @ORM\Entity
 */
class Legaldetails
{
/**
 * @var integer $legalid
 *
 * @ORM\Column(name="LegalID", type="integer", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $legalid;

/**
 * @var \Model\Entity\Company $company
 *
 * @ORM\Column(name="CompanyID", type="integer", nullable=false)
 * @ORM\OneToOne(targetEntity="\Model\Entity\Company", inversedBy="companyid")
 * @ORM\JoinColumn(name="companyid", referencedColumnName="companyid")
 */
private $company;

What is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:45:25+00:00Added an answer on May 28, 2026 at 7:45 am

    There’s a pretty clear explanation about how JOIN’s work with DQL here:

    With DQL when you write a join, it can be a filtering join (similar to the concept of join in SQL used for limiting or aggregating results) or a fetch join (used to fetch related records and include them in the result of the main query). When you include fields from the joined entity in the SELECT clause you get a fetch join

    this should be enough to get what you want (info about all companies with legal info loaded):

    $query = $em->createQuery('SELECT c, ld FROM \Model\Entity\Company c JOIN c.legaldetails ld');
    $companies = $query->getResult(); // array of Company objects with the legaldetails association loaded
    

    EDIT:

    i used a regular join in my query, so companies with no legal info won’t be returned in the query. if you want ALL companies even though they have no legal info loaded you should try with the left join as you were doing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to execute this query $qb = $this->_em->createQueryBuilder(); $qb->select(array('c', 'ld')) ->from('Model\Entity\Company', 'c') ->leftJoin('c.legaldetails',
I'm trying ro execute this dql query SELECT DISTINCT a FROM Ipf\Model\Entity\Transaction t INNER
I've a this query in mySQL (MyISAM): SELECT * FROM `links` WHERE `id` IN
Let's say I have this SQL query: declare @input varchar(20) select * from myTable
When I try to execute this statement in Oracle SQL Developer 2.1 a dialog
When I try to execute a view that includes tables from different schemas an
I am using JPA in my WAS 6.1. I try to execute this line:
I am trying to execute this SQL query prior to restoring a .BAK file
The db is PostgreSQL. When I try to execute a query with parameters, such
I'm using the MySql.Data dll from MySql and trying to execute a query to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.