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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:03:58+00:00 2026-05-29T04:03:58+00:00

I want to do something like that into Doctrine SQL… SELECT N.id as n_id,

  • 0

I want to do something like that into Doctrine SQL…

SELECT N.id as n_id, C.id as c_id, T.id as t_id, C.author_id, C.body as comment FROM `news` N 
LEFT JOIN thread T on T.id = N.id
LEFT JOIN comment C on C.thread_id = T.id
WHERE 1

So I have made this :

    $rsm = new ResultSetMapping;
    $rsm->addEntityResult('App\MyBundle\Entity\News', 'N');
    $cols = array ('id', 'title','date');
    foreach ($cols as $key => $col) {
        $rsm->addFieldResult('N', $col, $col);
    }
    // thread
    $rsm->addJoinedEntityResult('App\MyBundle\Entity\Thread' , 'T', 'N', 'thread');
    $rsm->addFieldResult('T', 't_id', 'id');

    $sql = 'SELECT N.id, N.title, N.date, T.id AS t_id FROM news N ' .
    'LEFT JOIN thread T ON T.id = N.id WHERE N.id = 1';
    $query = $this->_em->createNativeQuery($sql, $rsm);

But I have an error:

    Notice: Undefined index: thread in /vendor/doctrine/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 85       

I want to precise that there is no member link beetween the 2 entities.

Any ideas please?

Thanks for all

See ya

Sam

  • 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-29T04:03:59+00:00Added an answer on May 29, 2026 at 4:03 am

    According to the docs:

    The fourth and last parameter is the name of the field on the parent entity result that should contain the joined entity result.

    ref: http://www.doctrine-project.org/docs/orm/2.1/en/reference/native-sql.html#joined-entity-results

    you maybe missed to define the thread property in the News class that will receive your joined entity.

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

Sidebar

Related Questions

I want to do a select in MySql that combines several columns... something like
I want to build something like a network scanner, so that I see in
I want to have a route that looks something like: www.abc.com/companyName/Controller/Action/Id However, all the
I want to do this so that I can say something like, svn mv
I want to write a small program that should print something like testing CPU...
I want to have a template class that looks something like what I have
I want to parse a html content that have something like this: <div id=sometext>Lorem<br>
I want to write a C# method that can accept any number. Something like:
I want to write something that acts just like confirm() in javascript, but I
I want something like an std::map , but I only want to see if

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.