DoctrineExtensions icon indicating copy to clipboard operation
DoctrineExtensions copied to clipboard

Timestampable error if #[Assert\EnableAutoMapping]

Open tacman opened this issue 3 years ago • 1 comments

With automapping on, I'm getting validation errors for anything using the Timestampable trait

#[Assert\EnableAutoMapping]
class MyEntity {
    use Timestampable;

image

Both values are indeed set.

It has something to do with PHP8 and requiring that the entity be valid if there are types, including the annotations

    /**
     * @var \DateTime
     */
    protected $createdAt;

    /**
     * @var \DateTime
     */
    protected $updatedAt;

I'm not sure what the solution is. It could be

    /**
     * @var ?\DateTime
     */
    protected $createdAt=null;

    /**
     * @var ?\DateTime
     */
    protected $updatedAt=null;

so that the entity would be valid before it is persisted.

tacman avatar Jul 02 '22 10:07 tacman

Not sure if we can do something from the package because the extension sets these variables when persisting/updating.

so that the entity would be valid before it is persisted.

This is the main problem, entities should always be in a valid state, in this case when using Timestampable I usually also set those properties in the constructor.

franmomu avatar Jul 02 '22 19:07 franmomu

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Dec 30 '22 09:12 github-actions[bot]