Skip to content

Non anemic doctrine models are not supported #1747

@Nek-

Description

@Nek-

I'd like to write my model this way:

class Mail
{
    private $from;
    private $to;
    private $content;
    public function __construct($from, $to, $content)
    {
        $this->from = $from;
        $this->to = $to;
        $this->content = $content;
    }
}

My model looks like this following DDD guidelines.

But with ApiPlatform having this model with a correct (standard) configuration will result in an error of deserialization because fields are not considered as "writable" by the DoctrineOrmPropertyMetadataFactory class. Which is wrong on a Serializer point of view... and even on a Doctrine point of view as this entity is perfectly valid and its fields are also perfectly writable.

To me, this is an issue but @soyuka seems to disagree after a short discussion on slack.

There are many solutions for this problem inside ApiPlatform:

  • patch the DoctrineOrmPropertyMetadataFactory 
  • patch the SerializerPropertyMetadataFactory (after all if I say they are writable, then they are)
  • probably many more as there's also a "configuration" that may set the property writable by default (adding its documentation would be a great help)

There's a last thing about adding a custom PropertyMetadataFactoryInterface (that still needs some documentation) but I don't think it's relevant as to me, ApiPlatform must support this by default (to be compliant with Doctrine and Symfony)

[edit] this has nothing to do with the DoctrineOrmPropertyMetadataFactory.

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