symfony - @UniqueEntity does not work for me with a simple string property -
i have "company" entity 3 fields : id, name , slug. name unique.
when attempt create new company name used following error :
an exception occurred while executing 'insert companies (name, slug) values (?, ?)' params ["test", "test-1"]: sqlstate[23000]: integrity constraint violation: 1062 duplicate entry 'test' key 'uniq_8244aa3a5e237e06'
i don't know why, @uniqueentity not show error message. tried put line : @uniqueentity(fields={"name"}, groups={"company"})
here code of class :
<?php namespace project\userbundle\entity; use symfony\component\validator\constraints assert; use doctrine\common\collections\arraycollection; use gedmo\mapping\annotation gedmo; use doctrine\orm\mapping orm; use symfony\bridge\doctrine\validator\constraints\uniqueentity; /** * company * * @orm\table(name="companies") * @uniqueentity(fields={"name"}, message="form.error.name.unique") * @orm\entity */ class company { /** * @var integer * * @orm\column(name="id", type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ private $id; /** * @orm\column(type="string", length=50, unique=true) * @assert\notblank(message="form.error.name.not_blank"); * @assert\length(min="4", max="50", minmessage="form.error.name.length.min {{ limit }}", maxmessage="form.error.name.length.max {{ limit }}"); */ private $name; /** * @var string * * @orm\column(length=170, unique=true) * @gedmo\slug(fields={"name"}) */ private $slug; /** * @orm\onetomany(targetentity="project\userbundle\entity\user", mappedby="company") * @assert\valid */ private $users; }
thanks.
could test 3 possibilities , try default message? (but seems tried third one. maybe luck others) (btw, can not set groups option in uniqueentity annotation)
/** * user * * @uniqueentity("name") * @uniqueentity(fields="name") * @uniqueentity(fields={"name"}) */ class user { /** * @var string * * @orm\column(name="name", type="string", unique=true) * * @assert\notblank */ private $name; }
Comments
Post a Comment