AssocationOverride not creating ManyToOne column #5437

Open
opened 2026-01-22 15:07:44 +01:00 by admin · 0 comments
Owner

Originally created by @ricohumme on GitHub (Feb 28, 2017).

Hi,

I noticed that when extending an entity with a base class carrying a ManyToOne relation, this relation is not created as a column in the database.
Current doctrine orm version I'm using is: v2.5.6


namespace AppBundle\ProductBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

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

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\ProductBundle\Entity\Product")
     * @var Product
     */
    protected $product;

    ...

and for the subclass the following code:


namespace AppBundle\ProductBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 * @ORM\AssociationOverrides({
 *     @ORM\AssociationOverride(name="product",
 *      joinColumns={@ORM\JoinColumn(name="product_id")}
 *     )
 * })
 */
class ProductDigiSub extends ProductDigi
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue()
     * @ORM\Id()
     * @var integer
     */
    protected $id;

    ...

I have also tried adding the property $product to the sub class, but this doesn't do anything more than in current state. Same goes for omitting the AssocationOverrides. Same result.

Now, when I run doctrine:schema:update, the following query is executed on the database:

CREATE TABLE ProductDigiSub (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;

When I look at the column structure, the table ProductDigi has an id and product_id column whereas the ProductDigiSub table only has the id column

Can anyone else confirm this issue?

Originally created by @ricohumme on GitHub (Feb 28, 2017). Hi, I noticed that when extending an entity with a base class carrying a ManyToOne relation, this relation is not created as a column in the database. Current doctrine orm version I'm using is: v2.5.6 ```php <?php namespace AppBundle\ProductBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() * @ORM\MappedSuperclass() */ class ProductDigi { /** * @ORM\Column(type="integer") * @ORM\GeneratedValue() * @ORM\Id() * * @var int */ protected $id; /** * @ORM\ManyToOne(targetEntity="AppBundle\ProductBundle\Entity\Product") * @var Product */ protected $product; ... ``` and for the subclass the following code: ```php <?php namespace AppBundle\ProductBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() * @ORM\AssociationOverrides({ * @ORM\AssociationOverride(name="product", * joinColumns={@ORM\JoinColumn(name="product_id")} * ) * }) */ class ProductDigiSub extends ProductDigi { /** * @ORM\Column(type="integer") * @ORM\GeneratedValue() * @ORM\Id() * @var integer */ protected $id; ... ``` I have also tried adding the property $product to the sub class, but this doesn't do anything more than in current state. Same goes for omitting the AssocationOverrides. Same result. Now, when I run doctrine:schema:update, the following query is executed on the database: ``` CREATE TABLE ProductDigiSub (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB; ``` When I look at the column structure, the table _ProductDigi_ has an **id** and **product_id** column whereas the _ProductDigiSub_ table only has the **id** column Can anyone else confirm this issue?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5437