1
votes

I always follow the process found here to configure a child admin in sonata: Sonata/symfony - parent/child structure setup

Except this time, the parent admin is an entity and the child is a mongodb document.

/**
 * Class Child
 * @ODM\Document(collection="childs")
 */
class Child
{
    /**
     * @ODM\Id(strategy="INCREMENT")
     * @var int
     */
    protected $id;

    /**
     * @var parent
     * @ODM\Field(type="string", name="parent")
     * @Gedmo\ReferenceOne(type="entity", class="AppBundle\Entity\Parent",
     *          inversedBy="childs", identifier="parent_id", )
     */
    protected $parent;

[getters & setters]

}

/**
 * Parent
 *
 * @ORM\Table(name="parent")
 */
class Parent
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var ArrayCollection
     * @Gedmo\ReferenceMany(type="document", class="AppBundle\Document\Child", mappedBy="parent")
     */
    private $childs;

[getters + setters]
}

Now I added this line * @ODM\Field(type="string", name="parent") because it was throwing an error "undefined index: parent"

The error I have now is the following:

Class does not exist

with the stack trace:

in vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php at line 196

at ReflectionClass ->__construct ('') in vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php at line 196

at AbstractManagerRegistry ->getManagerForClass (null) in vendor/sonata-project/doctrine-mongodb-admin-bundle/Sonata/DoctrineMongoDBAdminBundle/Model/ModelManager.php at line 207

at ModelManager ->getDocumentManager (null) in vendor/sonata-project/doctrine-mongodb-admin-bundle/Sonata/DoctrineMongoDBAdminBundle/Model/ModelManager.php at line 164

at ModelManager ->find (null, '1') in vendor/sonata-project/admin-bundle/Form/DataTransformer/ModelToIdTransformer.php at line 45

at ModelToIdTransformer ->reverseTransform ('1') in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 1192

at Form ->viewToNorm ('1') in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 637

at Form ->submit ('1', true) in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 577

at Form ->submit (array('value' => '1'), true) in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 577

at Form ->submit (array('_sort_order' => 'ASC', '_sort_by' => object(FieldDescription), '_page' => '1', '_per_page' => '25', 'loan' => array('value' => '1'))) in vendor/sonata-project/admin-bundle/Datagrid/Datagrid.php at line 110

at Datagrid ->buildPager () in vendor/sonata-project/admin-bundle/Datagrid/Datagrid.php at line 265

at Datagrid ->getForm () in vendor/sonata-project/admin-bundle/Controller/CRUDController.php at line 210

at CRUDController ->listAction () at call_user_func_array (array(object(CRUDController), 'listAction'), array()) in app/bootstrap.php.cache at line 3109

at HttpKernel ->handleRaw (object(Request), '1') in app/bootstrap.php.cache at line 3071

at HttpKernel ->handle (object(Request), '1', true) in app/bootstrap.php.cache at line 3222

at ContainerAwareHttpKernel ->handle (object(Request), '1', true) in app/bootstrap.php.cache at line 2444

at Kernel ->handle (object(Request)) in web/app_dev.php at line 28

If I go into ModelToIdTransformer.php and manually set the classname, it all work. But I couldn't find out the way to configure it upstream.

Anyone had the same issue? or succeeded to make something like this work?

Thank you.

1

1 Answers

0
votes

I don't know how your admin class looks but usally I get the Undefined index ** message when I let an mapper (e.g. **list) guess the service type.

That's why I explicitely define it for instance in my $listMapper as 2nd parameter:

$listMapper->add('site', 'entity');

Maybe this already solves your initial problem.