0

There is an is_deleted column available in user table.
While a user is deleted then record not deleted just is_deleted is set to 1.
Then i create new user with same phone number. it's display unique validation error.

I want to skip is_deleted record in validation.

My UserProfiles Entity

<?php

/**
 * UserProfiles
 *
 * @ORM\Table(name="user_profiles")
 * @ORM\Entity
 */
 class UserProfiles
 {

/**
 * @var string
 *
 * @ORM\Column(name="phone_number", type="string", length=255, nullable=false)
 */
private $phoneNumber;

/**
 * @ORM\OneToOne(targetEntity="ApiBundle\Entity\Users", inversedBy="userProfile")
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
 */
private $user;

Validation constraint yml.

ApiBundle\Entity\UserProfiles:
constraints:
    - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
        fields: [phoneNumber]
        errorPath: phone_number
        message: "Phone number is already exists."

I want to add user.is_deleted in fields:[phoneNumber, user.is_deleted]

Uttam Panara
  • 541
  • 2
  • 10
  • 28

1 Answers1

2

I'm not sure UniqueEntity constraint could solve your issue here because is_deleted is on a different entity. Most probably you'll need to use Expression or Callback constraints so you can achieve more complex dynamic validation and get User fields from UserProfiles entity.

dlondero
  • 2,539
  • 1
  • 24
  • 33