1
votes

I am using symfony2 with the sonata admin bundle. Now I have an entity which has OneToOne association to another entity. I want the embed the show form of the child entity into the show form of the parent entity.

I have tried the form type "sonata_type_admin" but that only gives me a link to the sub entity.

Does anybody have a clue how to embed the show form of the sub entity?

Entity definitions:

Parent:

class Parent
{

    /**
     * @ORM\OneToOne(targetEntity="Child", mappedBy="parent")
     */
    private $child;
}

Child:

class Child
{

    /**
     * @ORM\OneToOne(targetEntity="Parent", mappedBy="child")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
     * })
     */
    private $parent;
}
1
Can you provide your entities definition ?M Khalid Junaid
Well my entities are pretty simple. I added the most important part of my entities to my question.sebbo

1 Answers

3
votes

Since you have a property in your parent entity which refers to your child entity you can call child fields in your configureShowFields methods to show fields from your child entity

protected function configureShowFields(ShowMapper $showMapper)
{
    $showMapper
        ->with('Child Fields', array('collapsed' => true))
        ->add('child.propertyName',null,array('label'=>'Label'))
        ->add('child.anotherPropertyName',null,array('label'=>'Label'))
        ... ;
}