Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine MappedSuperclass and unique constraints

I have a scenario where I need to use the MappedSuperclass functionality of Doctrine (using Symfony2), and also create a unique constraint on some superclass columns. Let's say:

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\MappedSuperclass
 */
class Base
{
    /**
     * @ORM\Column(type="integer", nullable=false)
     */
    private $someColumn;
}

/**
 * @ORM\Entity
 * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="column_idx", columns={"someColumn"})})
 */
class Concrete extends Base
{
}

The problem is at processing of @ORM\Table annotation during schema generation:

[Doctrine\DBAL\Schema\SchemaException]                          
There is no column with name 'someColumn' on table 'Concrete'.

Is there a way to define a unique constraint of a mapped superclass?

like image 932
krojew Avatar asked Jan 21 '26 17:01

krojew


1 Answers

Since the answer author didn't post the answer himself, let me quote him:

Try to use protected instead of private for entity field. You should always use protected or public for entity fields

like image 194
krojew Avatar answered Jan 23 '26 05:01

krojew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!