Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ObjectMapper] Allow constructor to be called when there are no mapped constructor parameters. #60797

Open
@anthonylex

Description

@anthonylex

Description

A constructor is not called when there are no constructor arguments.
However there are cases where you would want it to be able to be called such as mapping to a doctrine entity that has a collection so the collection is initialised:

class Article
{
    #[ORM\ManyToMany(targetEntity: Tag::class, cascade: ['persist'])]
    private Collection $tags;

    public function __construct()
    {
        $this->tags = new ArrayCollection();
    }
}

It results in this error:

<!-- The property App\Entity\Article::$tags is not readable because it is typed Doctrine\Common\Collections\Collection. You should initialize it or declare a default value instead. (500 Internal Server Error) -->

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions