RemoveNullableFromPrimaryKeyJoinColumnRector
Remove no-op "nullable" from join columns that are part of a primary key, on #[ORM\Id] to-one and many-to-many associations
use Doctrine\ORM\Mapping as ORM;
class User
{
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: Family::class)]
- #[ORM\JoinColumn(name: 'family_id', nullable: true)]
+ #[ORM\JoinColumn(name: 'family_id')]
private ?Family $family;
#[ORM\ManyToMany(targetEntity: Group::class)]
- #[ORM\JoinColumn(name: 'user_id', nullable: true)]
- #[ORM\InverseJoinColumn(name: 'group_id', nullable: true)]
+ #[ORM\JoinColumn(name: 'user_id')]
+ #[ORM\InverseJoinColumn(name: 'group_id')]
private Collection $groups;
}
Configure your rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\Doctrine\Orm36\Rector\Property\RemoveNullableFromPrimaryKeyJoinColumnRector;
return RectorConfig::configure()
->withRules([
RemoveNullableFromPrimaryKeyJoinColumnRector::class,
]);
PACKAGE:
doctrine/orm >=3.6 <6.0