flow-framework

Does Flow support the unique annotation from Doctrine?


Is something like this supported by Flow?

/**
 * @ORM\Entity
 * @UniqueEntity(
 *     fields={"host", "port"},
 *     errorPath="port",
 *     message="This port is already in use on that host."
 * )
 */
class Service
{

I need to validate that one title isn't used twice for one user.

Edit: Added model validator to check for uniqueness, but now it's checked in all actions: loading, updated etc.

Edit 2: "Solved" by checking in validator if object is new (not yet persisted). Still problem when updating already existent entity.


Solution

  • You can use the UniqueEntityValidator and only annotate the validator in the actions where you need to check the uniqueness. http://flowframework.readthedocs.org/en/latest/TheDefinitiveGuide/PartV/ValidatorReference.html#uniqueentityvalidator

    Alternatively, you could maybe use ValidationGroups to only validate with your existing model validator in the places you want it to happen. http://flowframework.readthedocs.org/en/latest/TheDefinitiveGuide/PartIII/Validation.html?highlight=validationgroups#advanced-feature-partial-validation