Resulta que tengo problemas para guardar mis formularios embebidos, asi 
que trate de hacer lo que es amigo Stefan me recomendo (al final de este 
mensaje), pero me arroja el siguiente error:

Unable to execute INSERT statement. [wrapped: SQLSTATE[23000]: Integrity
constraint violation: 1452 Cannot add or update a child row: a foreign
key constraint fails (`indepabis/persona`, CONSTRAINT `persona_FK_1`
FOREIGN KEY (`tipo_persona_id`) REFERENCES `tipo_persona` (`id`))]

THIS IS PART OF MY CODE:

class DenunciaForm extends BaseDenunciaForm
{
  public function configure()
  {
    parent::configure();
    unset($this['id'],
          $this['empleado_id'],
          $this['fecha'],
          $this['correlativo']
     );
.......
    if ($this->isNew())
    {
        $denunciante = new Persona();
        $this->getObject()->setPersonaRelatedByDenuncianteId(
$denunciante );
        $denuncianteForm = new PersonaForm( $denunciante, array('tipo'
=> 'natural'));

        $denunciado = new Persona();
        $this->getObject()->setPersonaRelatedByDenunciadoId( $denunciado );
        $denunciadoForm = new PersonaForm( $denunciado, array('tipo' =>
'juridica'));
    }else{
        $denunciante =
$this->getObject()->getPersonaRelatedByDenuncianteId();
        $denunciado = $this->getObject()->getPersonaRelatedByDenunciadoId();

        $denuncianteForm = new PersonaForm($denunciante, array('tipo' =>
strtolower($denunciante->getTipoPersona())) );
        $denunciadoForm = new PersonaForm($denunciado, array('tipo' =>
strtolower($denunciado->getTipoPersona())) );
    }
    $this->embedForm('denunciante', $denuncianteForm);
    $this->embedForm('denunciado', $denunciadoForm);

    //NOMBRE DEL FORMULARIO//
    $this->widgetSchema->setNameFormat('denuncia[%s]');
  }

  protected function doSave($con = null)
  {
    if (is_null($con))
    {
      $con = $this->getConnection();
    }

    $this->saveEmbeddedForms($con);

    //STATICS VALUES//
    $empleado_id =
sfContext::getInstance()->getUser()->getEmpleadoUsuario('id');
    $fecha = date('d').'-'.date('m').'-'.date('Y');
    $correlativo = Denuncia::obtenerCorrelativo();

    $this->getObject()->setEmpleadoId( $empleado_id );
    $this->getObject()->setFecha( $fecha );
    $this->getObject()->setCorrelativo( $correlativo );

    $this->getObject()->save($con);

  }

Alguien tiene alguna idea???

GRACIAS


Stefan Paschke escribió:
> Hi Germana
>
> On Nov 20, 2009, at 1:43 AM, Germana Oliveira wrote:
>
>   
>> Wel i have this in my lib/form/AudienciaForm.class.php
>>
>> public function configure()
>> {
>>    if ($this->isNew())
>>    {
>>        $conciliadorForm = new AudienciaConciliadorForm();
>>        $denuncianteForm = new PersonaForm(null, array('tipo' => 
>> 'natural'));
>>        $denunciadoForm = new PersonaForm(null, array('tipo' => 
>> 'juridica'));
>>     }
>>     
>
> so in the 'new' case, you embed the empty forms, but you don't connect their 
> objects (Persona $denunciate and Persona $denunciado) to the main Audienca 
> object. Symfony won't know that the objects in the Forms 'denunciante' and 
> 'denunciado' are actually to be aggregated to the Audienca, you'd need to do:
>
>   $denunciante = new Persona();
>   $this->object->setPersonaRelatedByDenuncianteId( $denunciante );
>   $denuncianteForm = new PersonaForm( $denunciante, array( 'tipo' => 
> 'natural' ) );
>   $denunciado = new Persona();
>   $this->object->setPersonaRelatedByDenunciadoId( $denunciado );
>   $denunciadoForm = new PersonaForm( $denunciado, array( 'tipo' => 'natural' 
> ) );
>
> and so on
>
>   
>> else{
>>        $clase = new AudienciaConciliador();
>>        $conciliador = $clase->getEmpleado();
>>        $conciliadorForm = new AudienciaConciliadorForm( $conciliador );
>>
>>        $denunciante = 
>> $this->getObject()->getPersonaRelatedByDenuncianteId();
>>        $denuncianteForm = new PersonaForm($denunciante);
>>
>>        $denunciado = $this->getObject()->getPersonaRelatedByDenunciadoId();
>>        $denunciadoForm = new PersonaForm($denunciado);
>>    }
>>     
>
> in the 'update' case, you do aggregate the objects correctly
>
>   
>>    $this->embedForm('conciliador', $conciliadorForm);
>>    $this->embedForm('denunciante', $denuncianteForm);
>>    $this->embedForm('denunciado', $denunciadoForm);
>> ....
>> }
>>     
>
> hope this helps
>
> Stefan
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "symfony users" group.
> To post to this group, send email to symfony-us...@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=.
>
>
>   


-- 
Germana Oliveira

Telefono:       0426 7457105
Correo-e:       germanaoliveirab_at_gmail.com
Blog:           http://slcarabobo.wordpress.com
                http://626f67.wordpress.com

Carabobo, Venezuela.

--

You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-us...@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