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 8020735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:46:19+00:00 2026-06-04T21:46:19+00:00

How can I execute this query using QueryBuilder in Symfony 2 SELECT um.id, sv.patentgroup_id,

  • 0

How can I execute this query using QueryBuilder in Symfony 2

SELECT um.id, sv.patentgroup_id, pm.portfolio_id, pp.id
FROM sv_patents sv
LEFT JOIN pm_patentgroups pm ON sv.patentgroup_id = pm.id
LEFT JOIN pm_portfolios pp ON pm.portfolio_id = pp.id
LEFT JOIN um_users um ON pp.user_id

The associations in entity classes are defined as

In SvPatents I have

 /**
 * @var PmPatentgroups
 *
 * @ORM\ManyToOne(targetEntity="PmPatentgroups")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="patentgroup_id", referencedColumnName="id")
 * })
 */
private $patentgroup;

In PmPatentgroups I have

/**
 * @var PmPortfolios
 *
 * @ORM\ManyToOne(targetEntity="PmPortfolios")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="portfolio_id", referencedColumnName="id")
 * })
 */
private $portfolio_id;

In PmPortfolios I have

/**
 * @var UmUsers
 *
 * @ORM\ManyToOne(targetEntity="UmUsers")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 * })
 */
private $user;

I tried this but it is giving me the whole results from the table looks like joins are not working propoerly

$repository = $this->getDoctrine()->getRepository('MunichInnovationGroupBundle:SvPatents');
        $qb = $repository->createQueryBuilder('sv')
        ->leftJoin('sv.patentgroup','pm')
        ->leftJoin('pm.portfolio_id','pp')
        ->leftJoin('pp.user','um')
        ->getQuery();
        $patents = $qb->getArrayResult();

I am quite new to Symfony2 and Doctorine2. I read the whole documentation but could not find such complex example actually i am bit confused with how the querybuilder build the query. It would be great if you explain it a little in simple words

Thanks in advance

  • 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-06-04T21:46:21+00:00Added an answer on June 4, 2026 at 9:46 pm

    I found the solution to my problem. If u looks for the records of a specific user in the table then you need to add one where clause. This is how your query should looks like

    $user_id = 1;
            $repository = $this->getDoctrine()->getRepository('MunichInnovationGroupBundle:SvPatents');
            $qb = $repository->createQueryBuilder('sv')
            ->select('sv')
            ->leftJoin('sv.patentgroup','pm')
            ->leftJoin('pm.portfolio_id','pp')
            ->leftJoin('pp.user','um')
            ->where('pp.user = :user_id')
            ->setParameter('user_id', $user_id)
            ->getQuery();
            $patents = $qb->getArrayResult();
    

    Thats all 🙂

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

Sidebar

Related Questions

Can I execute this sentence using grails? How? select @@global.max_allowed_packet; The why: I want
Hi I want to execute this query SELECT * FROM nm_ticket WHERE id_urgencia IN
so suppose I have this query SELECT COUNT(*) FROM (SELECT * FROM k JOIN
Can I execute a query like this? If not, can you give me a
Anybody knows how to execute this using the famous Cakephp ORM-based 'find' query function?
Anyone know how I can create this query using ActiveRecord rather than using SQL?
I am having an issue executing this query. SELECT * FROM gob_attachment WHERE CONTAINS
I am trying to execute a namedquery @NamedQuery(name=getEmployeeDetails,query=select e.username,e.email,e.image,e.firstname,e.lastname from Employee e where e.empid=?1)
I have a query like this Select * From Good where GoodCode in (Select
This ruby/rails construct always puzzles me: User.where(:name => Thiago).limit(3).using(:slave_one) This must execute from left-to-right,

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.