Why MappedSuperclass can not override another MappedSuperclass #6220

Closed
opened 2026-01-22 15:29:06 +01:00 by admin · 3 comments
Owner

Originally created by @pcabreus on GitHub (Apr 11, 2019).

Originally assigned to: @jwage on GitHub.

Bug Report

Q A
BC Break no
Version 2.6

Summary

If a create a MappedSuperclass and then I write another MappedSuperclass extending the first one and override some fields, it should works.

Current behavior

When I extend from the last one on the Entity, I get an error: Invalid field override .

How to reproduce

I created a dummy example for undestanding:

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\MappedSuperclass()
 */
class A
{
    /**
     * @var integer $id
     *
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue
     */
    protected $id;

    /**
     * @var
     * @ORM\Column(type="string")
     */
    protected $a;
} 

/**
 * @ORM\MappedSuperclass()
 * @ORM\AttributeOverrides({
 *      @ORM\AttributeOverride(name="a",
 *          column=@ORM\Column(
 *              length   = 140
 *          )
 *      )
 * })
 */
class B extends A
{
    /**
     * @var
     *
     * @ORM\Column(type="string")
     */
    protected $b;
}

/**
 * @ORM\Entity()
 * @ORM\Table()
 */
class C extends B
{
    /**
     * @var
     * @ORM\Column(type="string")
     */
    private $c;
}

When I update my schema I get Invalid field override named 'a' for class 'App\Entity\B'.

Expected behavior

A change of default length of column a to 140.

I have a real problem with AbstractLogEntry of Loggable GedmoDoctrineExtension which is required by other bundle that I extend from. So my Entity it's on 3rt level.

Originally created by @pcabreus on GitHub (Apr 11, 2019). Originally assigned to: @jwage on GitHub. ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.6 #### Summary If a create a `MappedSuperclass` and then I write another `MappedSuperclass` extending the first one and override some fields, it should works. #### Current behavior When I extend from the last one on the Entity, I get an error: `Invalid field override `. #### How to reproduce I created a dummy example for undestanding: ``` use Doctrine\ORM\Mapping as ORM; /** * @ORM\MappedSuperclass() */ class A { /** * @var integer $id * * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue */ protected $id; /** * @var * @ORM\Column(type="string") */ protected $a; } /** * @ORM\MappedSuperclass() * @ORM\AttributeOverrides({ * @ORM\AttributeOverride(name="a", * column=@ORM\Column( * length = 140 * ) * ) * }) */ class B extends A { /** * @var * * @ORM\Column(type="string") */ protected $b; } /** * @ORM\Entity() * @ORM\Table() */ class C extends B { /** * @var * @ORM\Column(type="string") */ private $c; } ``` When I update my schema I get `Invalid field override named 'a' for class 'App\Entity\B'. ` #### Expected behavior A change of default `length` of column `a` to `140`. I have a real problem with `AbstractLogEntry` of Loggable `GedmoDoctrineExtension` which is required by other bundle that I extend from. So my Entity it's on 3rt level.
admin added the Question label 2026-01-22 15:29:06 +01:00
admin closed this issue 2026-01-22 15:29:07 +01:00
Author
Owner

@jwage commented on GitHub (Apr 18, 2019):

I gave this a test and it looks like the AttributeOverrides need to be defined on the Entity and not the MappedSuperclass.

@jwage commented on GitHub (Apr 18, 2019): I gave this a test and it looks like the AttributeOverrides need to be defined on the Entity and not the MappedSuperclass.
Author
Owner

@pcabreus commented on GitHub (Apr 18, 2019):

So it can't be done like this???? Is it impossible??

@pcabreus commented on GitHub (Apr 18, 2019): So it can't be done like this???? Is it impossible??
Author
Owner

@jwage commented on GitHub (Apr 18, 2019):

I don't think so. I am not sure if this error is by design or if it should work.

@jwage commented on GitHub (Apr 18, 2019): I don't think so. I am not sure if this error is by design or if it should work.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6220