DDC-1097: Doctrine 2 ORM doesn't call constructor on object creation when using single table inheritance with abstract base class. #1372

Closed
opened 2026-01-22 13:12:06 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 3, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user sebak:

Hello,

I have a single table inheritance setup with an abstract base class and 2 concrete classes, like:
/****

  • @Entity
  • @Table(name="entry")
  • @InheritanceType("SINGLE_TABLE")
  • @DiscriminatorColumn(name="is_news", type="integer")
  • @DiscriminatorMap({"1" = "Popshouse\SiteBundle\Entity\News", "0" = "Popshouse\SiteBundle\Entity\Promotion"})
  • @HasLifecycleCallbacks
    _/
    abstract class Entry

    /_***
    • @Entity
      _/
      class News extends Entry{
      public function *_construct(){
      //do stuff
      }
      ...
      }

When I do $em->find('News',$id);
It creates the correct News object, but it hasn't called the constructor (so stuff "//do stuff" hasn't been executed). No problem when manually creating new News() object.

Originally created by @doctrinebot on GitHub (Apr 3, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user sebak: Hello, I have a single table inheritance setup with an abstract base class and 2 concrete classes, like: /**** - @Entity - @Table(name="entry") - @InheritanceType("SINGLE_TABLE") - @DiscriminatorColumn(name="is_news", type="integer") - @DiscriminatorMap({"1" = "Popshouse\SiteBundle\Entity\News", "0" = "Popshouse\SiteBundle\Entity\Promotion"}) - @HasLifecycleCallbacks _/ abstract class Entry{...} ----------------------------------------------- /_*** - @Entity _/ class News extends Entry{ public function *_construct(){ //do stuff } ... } When I do $em->find('News',$id); It creates the correct News object, but it hasn't called the constructor (so stuff "//do stuff" hasn't been executed). No problem when manually creating new News() object.
admin added the Bug label 2026-01-22 13:12:06 +01:00
admin closed this issue 2026-01-22 13:12:06 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 4, 2011):

Comment created by @beberlei:

Not calling the constructor is done by design, not a bug:

http://www.doctrine-project.org/docs/orm/2.0/en/reference/architecture.html#entities

Use @postLoad to perform operations for entities when they are reconstructed from the database.

@doctrinebot commented on GitHub (Apr 4, 2011): Comment created by @beberlei: Not calling the constructor is done by design, not a bug: http://www.doctrine-project.org/docs/orm/2.0/en/reference/architecture.html#entities Use @postLoad to perform operations for entities when they are reconstructed from the database.
Author
Owner

@doctrinebot commented on GitHub (Apr 4, 2011):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Apr 4, 2011): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1372