Skip to content

OneToOne inverse yields doctrine.associationType false positive #715

Description

@bobvandevijver

Consider the following construct

#[ORM\Entity]
class A {
  #[ORM\OneToOne(inversedBy: 'a', cascade: ['persist'], fetch: 'EXTRA_LAZY')]
  private ?B $b = null;
}

#[ORM\Entity]
class B {
  #[ORM\OneToOne(mappedBy: 'b')]
  private A $a; // Default in constructor
}

This results in:

 ------ ----------------------------------------------------------------------------------------------------------------
  Line   src/Entity/B.php
 ------ ----------------------------------------------------------------------------------------------------------------
  29     Property App\Entity\B::$a type mapping mismatch: database can contain
         App\Entity\A|null but property expects App\Entity\A.
         🪪  doctrine.associationType
 ------ ----------------------------------------------------------------------------------------------------------------

However, this is a false positive, as the $a never even makes it to the database with this construction. The A holds an optional reference to the B object.

According to doctrine, when trying to add a join column definition to disallow a null value.

App\Entity\B#a is a OneToOne inverse side, which does not allow join columns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions