Date custom constraint validation

I wrote custom constraint for my entity where I have startDate and endDate where I want to avoid overlapping when saving new ones.

<?php

namespace AppEntity;

use DoctrineORMMapping as ORM;
use AppValidatorConstraintsNotOverlapping;

/**
 */
class Product
{
    /**
     * @ORMId()
     * @ORMGeneratedValue()
     * @ORMColumn(type="integer")
     */
    private $id;

    /**
     * @ORMColumn(type="date", nullable=false)
     */
    private $startDate;

    /**
     * @ORMColumn(type="date", nullable=true)
     */
    private $endDate;
 }

Then I completly use this gist : full example ; Which I think is the best solution for me.

But as I am new at writing custom constraint validations can someone clarify how I can now use it? Is there something I should include in an entity or directly in service method where I am persisting entity?

What am I missing here?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *