Skip to content

Make:entity --regenerate : OneToOne relationship bug in the setter #195

@JayPe69

Description

@JayPe69

Hello,

I have one entity Organization with a team property

class RefOrganization

    /**
     * One Organization has One team
     * @ORM\OneToOne(targetEntity="RefTeam", mappedBy="organization")
     */
    private $team;

I have a second entity Team with a Organization property

class RefTeam

    /**
     * One Team has one Organization
     * @ORM\OneToOne(targetEntity="RefOrganization", inversedBy="team")
     * @ORM\JoinColumn(name="ORGANIZATION_ID", referencedColumnName="ID", nullable=true)
     */
    private $organization;

With the following code, I got a OneToOne relationship between both entities.
However, when lauching the Make:Entity --regenerate to get back all setters / getters,

In the RefOrganization entity, it generates the following setter for the team :

    public function setTeam(?RefTeam $team): self
    {
        $this->team = $team;

        // set (or unset) the owning side of the relation if necessary
        $newOrganization = $team === null ? null : $this;
        if ($newOrganization !== $team->getOrganization()) {
            $team->setOrganization($newOrganization);
        }

        return $this;
    }

When creating the RefOrganization without team (as it's nullable), we have an error because of the :

if ($newOrganization !== $team->getOrganization()) 

call method getOrganization of null object

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBug Fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions