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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:41:00+00:00 2026-06-15T12:41:00+00:00

I have two entities that share an abstract class creating class table inheritance. I

  • 0

I have two entities that share an abstract class creating class table inheritance. I can query for the entities by using the abstract class’ repository and get all the entities that extend the abstract class as the result.

$qb = $this->createQueryBuilder('c')
    ->where('c.featured = true')
    ->orderBy('c.sticky', 'DESC')
    ->addOrderBy('c.weight', 'ASC')
    ->setFirstResult($offset)
    ->setMaxResults($limit);

// Returns 8 results, results in 34 queries

The sub classes contain ManyToMany relationships to other entities so if I query in this manner, those relationships result in additional queries since they are not being joined. How can you query for entities extending an abstract class and join their columns? I tried adding multiple from statements with left joins but the query returned fewer than the expected 8 results. That query builder looks something like this:

$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select(array(
    'a', 'artist', 'country', 
    't', 'artwork', 'user'))
   ->from('AcmeArtworkBundle:Artwork', 'a')
   ->from('AcmeTourBundle:Tour', 't')
   ->leftJoin('a.artist', 'artist')
   ->leftJoin('a.country', 'country')
   ->leftJoin('t.artwork', 'artwork')
   ->leftJoin('t.user', 'user')
   ->where('a.featured = true')
   ->andWhere('t.featured = true')
   ->orderBy('a.sticky', 'DESC')
   ->addOrderBy('t.sticky', 'DESC')
   ->addOrderBy('a.weight', 'ASC')
   ->addOrderBy('t.weight', 'ASC')
   ->setFirstResult($offset)
   ->setMaxResults($limit);

// 5 results :-(
  • 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-15T12:41:02+00:00Added an answer on June 15, 2026 at 12:41 pm

    From the information provided by the link provided by @Ocramius, By default Doctrine loads entities using lazy loading. Associations are fetched only when they need to be. You can tell Doctrine to automatically fetch an association by setting the fetch mode to EAGER.

    /**
     * @var string $date
     *
     * @ORM\ManyToOne(targetEntity="Date", inversedBy="artwork", cascade={"persist"}, fetch="EAGER")
     * @ORM\JoinColumn(name="date", referencedColumnName="id")
     */
    private $date;
    

    It’s important to note that you can actually cause more queries to be run by doing this if you aren’t careful.

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

Sidebar

Related Questions

I'm using core data in my app. I have two entities that are related:
I have two entities that are something like that: public class Movie { public
I have a situation where I have two entities that share a primary key
I have created Generic Repository and I have two entities that i need to
I have a two entities that are related like so. public class User {
I have two Doctrine entities that have a one-to-many relationship, like this: License class
I have two entities: Article and Category. That have a many to many table:
I have two entities: Event and Comment. @Entity @Table(name = events) public class Event
Assume that I have two entities as follows: class Blog { public Blog() {
I have two entities Visita and Cliente that implements respectively two interfaces IVisita and

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.