Doctrine superclass inheritance - indexes are not inherited #5187

Closed
opened 2026-01-22 15:00:59 +01:00 by admin · 5 comments
Owner

Originally created by @nacholibre on GitHub (Jul 10, 2016).

Originally assigned to: @Ocramius on GitHub.

/**
 * @MappedSuperclass
 * @Table(indexes={@Index(name="idx", columns={"name"})})
 */
class BaseSuperClass
{
    /** @Column(type="string") */
    protected $name;

    // ... more fields and methods
}

/** @Entity */
class EntitySubClass extends BaseSuperClass
{
    /** @Id @Column(type="integer") */
    private $id;

    // ... more fields and methods
}

Name index is not inherited from BaseSuperClass, it there any way to achieve this?

Originally created by @nacholibre on GitHub (Jul 10, 2016). Originally assigned to: @Ocramius on GitHub. ``` /** * @MappedSuperclass * @Table(indexes={@Index(name="idx", columns={"name"})}) */ class BaseSuperClass { /** @Column(type="string") */ protected $name; // ... more fields and methods } /** @Entity */ class EntitySubClass extends BaseSuperClass { /** @Id @Column(type="integer") */ private $id; // ... more fields and methods } ``` Name index is not inherited from `BaseSuperClass`, it there any way to achieve this?
admin added the Invalid label 2026-01-22 15:00:59 +01:00
admin closed this issue 2026-01-22 15:00:59 +01:00
Author
Owner

@Ocramius commented on GitHub (Jul 11, 2016):

@Table is not valid on a mappedsuperclass.
On 10 Jul 2016 16:46, "Yoan Arnaudov" notifications@github.com wrote:

/**

  • @MappedSuperclass

  • @Table(indexes={@Index(name="idx", columns={"name"})})
    /
    class BaseSuperClass
    {
    /
    * @Column(type="string") */
    protected $name;

    // ... more fields and methods
    }

/** @Entity /
class EntitySubClass extends BaseSuperClass
{
/
* @Id @Column(type="integer") */
private $id;

// ... more fields and methods

}

Name index is not inherited from BaseSuperClass, it there any way to
achieve this?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/5928, or mute the thread
https://github.com/notifications/unsubscribe/AAJakHTYvOtepqSIm5ZYPA1b08TXvRmAks5qUQXSgaJpZM4JI2Uw
.

@Ocramius commented on GitHub (Jul 11, 2016): @Table is not valid on a mappedsuperclass. On 10 Jul 2016 16:46, "Yoan Arnaudov" notifications@github.com wrote: > /** > - @MappedSuperclass > - @Table(indexes={@Index(name="idx", columns={"name"})}) > _/ > class BaseSuperClass > { > /_\* @Column(type="string") */ > protected $name; > > // ... more fields and methods > } > > /*\* @Entity _/ > class EntitySubClass extends BaseSuperClass > { > /_\* @Id @Column(type="integer") */ > private $id; > > ``` > // ... more fields and methods > ``` > > } > > Name index is not inherited from BaseSuperClass, it there any way to > achieve this? > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > https://github.com/doctrine/doctrine2/issues/5928, or mute the thread > https://github.com/notifications/unsubscribe/AAJakHTYvOtepqSIm5ZYPA1b08TXvRmAks5qUQXSgaJpZM4JI2Uw > .
Author
Owner

@nacholibre commented on GitHub (Jul 11, 2016):

Okay, but is there any way to achieve this?

@nacholibre commented on GitHub (Jul 11, 2016): Okay, but is there any way to achieve this?
Author
Owner

@alexgurrola commented on GitHub (Jan 18, 2017):

@nacholibre or @Ocramius, Did you find a way to inherit indexes with a mapped superclass? I have tons of entities that would benefit from a feature as such.

@alexgurrola commented on GitHub (Jan 18, 2017): @nacholibre or @Ocramius, Did you find a way to inherit indexes with a mapped superclass? I have tons of entities that would benefit from a feature as such.
Author
Owner

@Ocramius commented on GitHub (Jan 18, 2017):

Did you find a way to inherit indexes with a mapped superclass?

Listeners - simply attach a listener that, when the metadata loads, adds the indexes to all classes that are instance of a certain mapped superclass.

@Ocramius commented on GitHub (Jan 18, 2017): > Did you find a way to inherit indexes with a mapped superclass? Listeners - simply attach a listener that, when the metadata loads, adds the indexes to all classes that are instance of a certain mapped superclass.
Author
Owner

@ThomasLandauer commented on GitHub (Feb 2, 2020):

I posted a full solution for the listener suggested by @Ocramius at https://stackoverflow.com/a/60029840/1668200

@ThomasLandauer commented on GitHub (Feb 2, 2020): I posted a full solution for the listener suggested by @Ocramius at https://stackoverflow.com/a/60029840/1668200
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5187