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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:36:19+00:00 2026-05-24T21:36:19+00:00

NOTE : if what I want is not possible, a not possible answer will

  • 0

NOTE : if what I want is not possible, a “not possible” answer will be accepted

In the Doctrine 2 documentation about inheritance mapping, it says there are 2 ways :

  • Single table inheritance (STI)
  • Class table inheritance (CTI)

For both, there is the warning :

If you use a STI/CTI entity as a many-to-one or one-to-one entity you should never use one of the classes at the upper levels of the inheritance hierachy as “targetEntity”, only those that have no subclasses. Otherwise Doctrine CANNOT create proxy instances of this entity and will ALWAYS load the entity eagerly.

So, how can I proceed to use inheritance with an association to the base (abstract) class ? (and keep the performance of course)


Example

A user has many Pet (abstract class extended by Dog or Cat).

What I want to do :

class User {
    /**
     * @var array(Pet) (array of Dog or Cat)
     */
    private $pets;
}

Because of the warning in Doctrine documentation, I should do that :

class User {
    /**
     * @var array(Dog)
     */
    private $dogs;
    /**
     * @var array(Cat)
     */
    private $cats;
}

This is annoying, because I loose the benefits of inheritance !

Note : I didn’t add the Doctrine annotations for the mapping to DB, but you can understand what I mean

  • 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-24T21:36:19+00:00Added an answer on May 24, 2026 at 9:36 pm

    I’m tired, but this seems like much ado about nothing.

    You missed the important bit of that warning:

    If you use a STI/CTI entity as a many-to-one or one-to-one entity

    That’s not the case in your example! If you had not omitted the doctrine annotations, you might have noticed.

    The association User::pets is OneToMany, not [One|Many]ToOne. One user has many pets.

    The inverse association is OneToOne, but it’s targeting User, which has no inheritance.

    Robin’s answer should have been a good hint — you can log the sql queries and see what doctrine actually does to your database!


    The bad-for-performance scenario is something like:

    abstract class Pet { ... }
    
    class Cat extends Pet { ... } 
    
    class Dog extends Pet { ... }
    
    class Collar {
       /**
        * @Column(length="16")
        */
    
       protected $color;
       /**
        * ManyToOne(targetEntity="Pet")
        */
       protected $owner;
    }
    

    Now, if you wanted to iterate over all the blue collars, Doctrine runs into some trouble. It doesn’t know what class $owner is going to be, so it can’t use a Proxy. Instead, it’s forced to eagerly load $owner to find out whether it’s a Cat or a Dog.

    This isn’t a problem for OneToMany or ManyToMany relationships, because in that case, lazy loading works fine. Instead of a proxy, you get a PersistentCollection. And a PersistentCollection is always just a PersistentCollection. It doesn’t care about it’s own contents until you actually ask for them. So lazy loading works fine.

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

Sidebar

Related Questions

Everything I'm finding via google is garbage... Note that I want the answer in
Note This is not a REBOL-specific question. You can answer it in any language.
Before I ask this, do note: I want this for debugging purposes. I know
I want to show terms and condition note on my website. I dont want
Note : The code in this question is part of deSleeper if you want
I want to be able to add a little note, at the beginning of
I want to be able to convert between the Gregorian and Julian calendars (note:
I want to perform simple validation against multiple fields. Please note these fields are
I want to create an XSD which can generate the following XML. <note> <email:to>abc@def.com</email:to>
I just want to get a quick htaccess redirection. ie: domain.com/subfolderGreen --> domain.com/index.php?folder=subfolderGreen (note

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.