Skip to content

Cannot satisfy not nullable OneToOne inverse side #97

@noemi-salaun

Description

@noemi-salaun

I cannot find a way to satisfy the case

Property App\User::$stats type mapping mismatch: database can contain App\UserStats|null but property expects App\UserStats.

I have the following mapping :

<?php

class User
{

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

    /**
     * @var UserStats
     *
     * @ORM\OneToOne(targetEntity="App\UserStats", mappedBy="user")
     */
    protected $stats;

    // ... other properties

}

class UserStats
{
    
    /**
     * @var User
     *
     * @ORM\Id
     * @ORM\OneToOne(targetEntity="App\User", inversedBy="stats")
     */
    private $user;
    
    // ... other properties

}

If I add @ORM\JoinColumn(nullable=false) on User::$stats property then Doctrine is broken because JoinColumn annotation is expected on the owning side of the one to one relationship.

So I'm stuck with this case, because I can't explain to phpstan that my property isn't nullable :/

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