I am trying to verify the uniqueness of an object submitted from a form using the uniqueness check constraint in several fields.
The object code, which must be unique, has two fields: fieldA and fieldB , both unique:
/**
* @ORM\Table(name="mytable")
* @ORM\Entity
* @DoctrineAssert\UniqueEntity(fields = {"fieldA", "fieldB"})
*/
class myClass
{
/**
* @ORM\Column(name="fieldA", type="string", length=128, unique=true)
*/
protected $fieldA;
/**
* @ORM\Column(name="fieldB", type="string", length=128, unique=true)
*/
protected $fieldB;
}
Suppose I already have an entry in the database with the values:
- fieldA = 'value_a', fieldB = 'value_b'
Now, when I try to submit another form with values (fieldA = 'value_a', fieldB = 'value_c') from the form, Symfony2 generates a request to verify uniqueness:
SELECT ... FROM ... WHERE fieldA = ? AND fieldB = ? ('value_a', 'value_c')
, , , , fieldA . ( SQL "value_a".)
Symfony2 UniqueEntity :
- ( ), . , , .
, .
UniqueEntityValidator ( 94), "findBy" . "" , .
- , ?