Emerson Minero
Emerson Minero

Reputation: 608

Is it possible to implement sonata_type_collection within sonata_type_collection?

viewing this post I believe that it is possible, but i don't know how he has configured his entities.

Sonata Admin Bundle Type Collection Customisation

I have my Admin files identical to him. But these other post I found that this capability is not supported for sonata.

https://github.com/sonata-project/SonataAdminBundle/issues/262

https://github.com/sonata-project/SonataAdminBundle/issues/802

Please, could someone suggest something to figure out it!

Update: (Dour High Arch)

 .../SimBundle/Admin/EmpleadoAdmin.php
protected function configureFormFields(FormMapper $formMapper)
{
      $formMapper
        ->with('Tecnico')
           ->add('empleadoTecnico', 'sonata_type_collection'), 
                            array('edit' => 'inline','sortable'=>'pos','inline' => 'table'))
        ->end()
        ;

}

  .../SimBundle/Admin/TecnicoAdmin.php
protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('salarioHora',null,array('label'=>'Salario por hora:'))
        ->with('Experiencia')
        ->add('experienciaLaboral', 'sonata_type_collection', array('label'=>'Experiencia Laboral:'),
                                                 array('edit' => 'inline','sortable'=>'pos','inline' => 'table'))
        ->end()


        ;   
}

   .../SimBundle/Admin/EmpExperienciaLaboralAdmin.php
protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('nombreJefeInmediato',null,array('label'=>'Nombre Jefe Inmediato:'))      
        ;   
}

Entities

...\SimBundle\Entity;

class EmpEmpleado {

/**
 *
 * @ORM\OneToMany(targetEntity="Tecnico", mappedBy="idEmpleado", cascade={"all"}, orphanRemoval=true)
 *
 */
private $empleadoTecnico;

}

...\SimBundle\Entity;

class Tecnico {

/**
 * @var \EmpEmpleado
 *
 * @ORM\OneToOne(targetEntity="EmpEmpleado", inversedBy="empleadoTecnico")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="id_empleado", referencedColumnName="id")
 * })
 */
private $idEmpleado;

/**
 *
 * @ORM\OneToMany(targetEntity="EmpExperienciaLaboral", mappedBy="idEmpleado", cascade={"all"}, orphanRemoval=true)
 *
 */
private $experienciaLaboral;

}

...\SimBundle\Entity;

class EmpExperienciaLaboral {

/**
 * @var \Tecnico
 *
 * @ORM\ManyToOne(targetEntity="Tecnico", inversedBy="experienciaLaboral")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="id_empleado", referencedColumnName="id")
 * })
 */
private $idEmpleado;

}

When i'm trying add experienciaLaboral, it's faild: Fatal error: Call to a member function getName() on a non-object in

Schema looks like this:

EmpEmpleado --> (OneToMany) --> Tecnico --> (OneToMany) --> EmpExperienciaLaboral

(sorry, i can't to put the image, this my first question and I don't have 10 reputations)

Upvotes: 1

Views: 1570

Answers (1)

rande
rande

Reputation: 666

No you cannot have nested collection... the limitation is due to how admin uniqid works. The unique id is used to avoid clash between element sharing the same admin.

For now adminId is not a stack, you only have adminId and childAdminId... in your case you need to have a childChildAdminId ...

Upvotes: 4

Related Questions