Ah, that makes sense.

So the validation framework was not taking into account that the Cidade was
already persisted, and was assuming it was a duplicate. So now you're going
to use validation groups to exclude the Cidade from the validation?

On Wed, May 11, 2011 at 7:10 AM, elcabong <elcabong....@gmail.com> wrote:

> The solution is  validation groups.
>
> Tanks
>
> On 10 maio, 08:53, elcabong <elcabong....@gmail.com> wrote:
> > Controller:
> >
> > namespace MCP\AdminBundle\Controller;
> >
> > use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
> > use MCP\AdminBundle\Form\ParceiroType;
> > use Symfony\Component\HttpFoundation\RedirectResponse;
> > use Symfony\Bundle\FrameworkBundle\Controller\Controller;
> >
> > class ParceiroController extends Controller
> > {
> >
> >         ....
> >
> >         public function createAction()
> >     {
> >         $form = $this->get('form.factory')->create(new ParceiroType());
> >
> >         $form->bindRequest($this->get('request'));
> >
> >         if($form->isValid()) {
> >
> >                 $this->get('admin.repository.parceiro')->save($form-
> >
> > >getData());
> >
> >             $this->get('session')->setFlash('msg.add.sucess',
> > 'success');
> >             return
> $this->redirect($this->generateUrl('admin_parceiro_list'));
> >
> >         }
> >
> >         return
> $this->get('templating')->renderResponse('MCPAdminBundle:Parceiro:new.html.twig',
> array(
> >
> >                 'form' => $form->createView()
> >         ));
> >
> >     }
> >
> >    ......
> >
> > }
> >
> > Repository:
> >
> > namespace MCP\AdminBundle\Repository;
> >
> > use Symfony\Component\Security\Core\Encoder
> > \MessageDigestPasswordEncoder;
> > use MCP\AdminBundle\Entity\Parceiro;
> > use Doctrine\ORM\EntityRepository;
> >
> > /**
> >  * ParceiroRepo
> >  *
> >  * This class was generated by the Doctrine ORM. Add your own custom
> >  * repository methods below.
> >  */
> > class ParceiroRepo extends EntityRepository
> > {
> >         public function save(Parceiro $parceiro) {
> >
> >                 $parceiro->setSalt(md5(time()));
> >                 $password = $parceiro->getSenha();
> >
> >                 $encoder = new MessageDigestPasswordEncoder('sha512',
> true, 10);
> >                 $encodePassword = $encoder->encodePassword($password,
> $parceiro-
> >
> > >getSalt());
> >
> >                 $parceiro->setSenha($encodePassword);
> >
> >                 $objectManager = $this->getEntityManager();
> >                 $objectManager->persist($parceiro);
> >                 $objectManager->flush();
> >         }
> >
> >         .....
> >
> > }
> >
> > Anything else??
> >
> > Tanks.
> >
> > On 9 maio, 21:58, Donald Tyler <chekot...@gmail.com> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > The only thing I can think is happening is that the Cidade is becoming
> > > detached from the Entity Manager somehow, and when you persist the new
> > > Parceiro, it's actually trying to persist the Cidade again.
> >
> > > Can you post the full code for the Controller action that's throwing
> the
> > > Unique Constraint violation?
> >
> > > On Mon, May 9, 2011 at 9:19 AM, elcabong <elcabong....@gmail.com>
> wrote:
> > > > Yes
> >
> > > > What can I try to do for this not to happen??
> >
> > > > Tanks
> >
> > > > On May 9, 9:51 am, Donald Tyler <chekot...@gmail.com> wrote:
> > > > > You said that you weren't creating a new Cidade, so that means that
> > > > > the Parceiro
> > > > > was using an existing Cidade, correct?
> >
> > > > > On Mon, May 9, 2011 at 7:44 AM, elcabong <elcabong....@gmail.com>
> wrote:
> > > > > > Thisvalidationconfig:
> >
> > > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > > <constraint-mapping xmlns="
> http://symfony.com/schema/dic/constraint-
> > > > > > mapping"
> > > > > >        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > > > >        xsi:schemaLocation="
> > > > > >http://symfony.com/schema/dic/constraint-mapping
> > > > > >http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd
> ">
> >
> > > > > >        <class name="MCP\AdminBundle\Entity\Cidade">
> > > > > >                <property name="nome">
> > > > > >                        <constraint name="NotBlank">
> > > > > >                                <option name="message">Por favor
> digite
> > > > um
> > > > > > nome</option>
> > > > > >                        </constraint>
> > > > > >                        <constraint name="MinLength">
> > > > > >                                <option name="limit">6</option>
> > > > > >                                <option name="message">Nome muito
> > > > > > pequeno</option>
> > > > > >                        </constraint>
> > > > > >                        <constraint name="MaxLength">
> > > > > >                                <option name="limit">90</option>
> > > > > >                                <option name="message">Nome muito
> > > > > > longo</option>
> > > > > >                        </constraint>
> > > > > >                        <constraint
> > > > name="MCP\AdminBundle\Validator\Unique">
> > > > > >                                <option
> name="property">nome</option>
> > > > > >                                <option
> > > > > > name="entity">MCP\AdminBundle\Entity\Cidade</option>
> > > > > >                                <option name="message">Cidade já
> > > > > > cadastrada</option>
> > > > > >                        </constraint>
> > > > > >                </property>
> > > > > >        </class>
> >
> > > > > >        <class name="MCP\AdminBundle\Entity\Usuario">
> > > > > >                <property name="senha">
> > > > > >                        <constraint name="MinLength">
> > > > > >                                <option name="limit">6</option>
> > > > > >                                <option name="message">A senha
> precisa
> > > > ser
> > > > > > no mínimo 6 dígitos</
> > > > > > option>
> > > > > >                        </constraint>
> > > > > >                        <constraint name="True">
> > > > > >                                <option name="message">Erro
> > > > senha</option>
> > > > > >                        </constraint>
> > > > > >                </property>
> > > > > >        </class>
> >
> > > > > >        <class name="MCP\AdminBundle\Entity\Parceiro">
> >
> > > > > >        </class>
> >
> > > > > > </constraint-mapping>
> >
> > > > > > On May 9, 9:32 am, Donald Tyler <chekot...@gmail.com> wrote:
> > > > > > > I don't see any info on your class annotations for what
> properties
> > > > are
> > > > > > > required to be unique.
> >
> > > > > > > On Mon, May 9, 2011 at 7:27 AM, elcabong <
> elcabong....@gmail.com>
> > > > wrote:
> > > > > > > > Entities:
> >
> > > > > > > > class Cidade
> > > > > > > > {
> > > > > > > >    /**
> > > > > > > >     * @var string $nome
> > > > > > > >     */
> > > > > > > >    private $nome;
> >
> > > > > > > >    /**
> > > > > > > >     * @var boolean $ativo
> > > > > > > >     */
> > > > > > > >    private $ativo;
> >
> > > > > > > >    /**
> > > > > > > >     * @var bigint $id
> > > > > > > >     */
> > > > > > > >    private $id;
> >
> > > > > > > >    /**
> > > > > > > >     * Set nome
> > > > > > > >     *
> > > > > > > >     * @param string $nome
> > > > > > > >     */
> > > > > > > >    public function setNome($nome)
> > > > > > > >    {
> > > > > > > >        $this->nome = $nome;
> > > > > > > >    }
> >
> > > > > > > >    /**
> > > > > > > >     * Get nome
> > > > > > > >     *
> > > > > > > >     * @return string $nome
> > > > > > > >     */
> > > > > > > >    public function getNome()
> > > > > > > >    {
> > > > > > > >        return $this->nome;
> > > > > > > >    }
> >
> > > > > > > >    /**
> > > > > > > >     * Set ativo
> > > > > > > >     *
> > > > > > > >     * @param boolean $ativo
> > > > > > > >     */
> > > > > > > >    public function setAtivo($ativo)
> > > > > > > >    {
> > > > > > > >        $this->ativo = $ativo;
> > > > > > > >    }
> >
> > > > > > > >    /**
> > > > > > > >     * Get ativo
> > > > > > > >     *
> > > > > > > >     * @return boolean $ativo
> > > > > > > >     */
> > > > > > > >    public function getAtivo()
> > > > > > > >    {
> > > > > > > >        return $this->ativo;
> > > > > > > >    }
> >
> > > > > > > >    /**
> > > > > > > >     * Get id
> > > > > > > >     *
> > > > > > > >     * @return bigint $id
> > > > > > > >     */
> > > > > > > >    public function getId()
> > > > > > > >    {
> > > > > > > >        return $this->id;
> > > > > > > >    }
> >
> > > > > > > > }
> >
> > > > > > > > class Parceiro extends Usuario
> > > > > > > > {
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $tipoPessoa
> > > > > > > >     */
> > > > > > > >    private $tipoPessoa;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $nomeEmpresa
> > > > > > > >     */
> > > > > > > >    private $nomeEmpresa;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $numeroDocumento
> > > > > > > >     */
> > > > > > > >    private $numeroDocumento;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $inscrestadual
> > > > > > > >     */
> > > > > > > >    private $inscrestadual;
> >
> > > > > > > >    /**
> > > > > > > >     * @var boolean $isentoInscr
> > > > > > > >     */
> > > > > > > >    private $isentoInscr;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $nome
> > > > > > > >     */
> > > > > > > >    private $nome;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $sobrenome
> > > > > > > >     */
> > > > > > > >    private $sobrenome;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $urlsite
> > > > > > > >     */
> > > > > > > >    private $urlsite;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $endereco
> > > > > > > >     */
> > > > > > > >    private $endereco;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $complemento
> > > > > > > >     */
> > > > > > > >    private $complemento;
> >
> > > > > > > >    /**
> > > > > > > >     * @var integer $numero
> > > > > > > >     */
> > > > > > > >    private $numero;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $cep
> > > > > > > >     */
> > > > > > > >    private $cep;
> >
> > > > > > > >    /**
> > > > > > > >     * @var string $telefone
> > > > > > > >     */
> > > > > > > >    private $telefone;
> >
> > > > > > > >    /**
> > > > > > > >     * @var MCP\AdminBundle\Entity\Cidade
> > > > > > > >     */
> > > > > > > >    private $cidade;
> >
> > > > > > > >    /**
> > > > > > > >     * Set tipoPessoa
> > > > > > > >     *
> > > > > > > >     * @param string $tipoPessoa
> > > > > > > >     */
> > > > > > > >    public function setTipoPessoa($tipoPessoa)
> > > > > > > >    {
> > > > > > > >        $this->tipoPessoa = $tipoPessoa;
> > > > > > > >    }
> >
> > > > > > > >    /**
> >
> > ...
> >
> > mais »
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to symfony-users@googlegroups.com
> To unsubscribe from this group, send email to
> symfony-users+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to