I had missed use Doctrine\ORM\Mapping as ORM; Adding this line in Media entity fixed the issue for me. And my current Entity structure is same as discussed in the previous comment
On Thursday, June 2, 2016 at 7:19:31 PM UTC+5:45, [email protected] wrote: > > Hi all, > I've a problem when trying to load a sonata_type_model_list field within a > sonata_type_admin. It gives me the following error: > >> Impossible to invoke a method ("id") on a null variable in >> SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig at line 60 >> > > *My entities:* > > - AppBundle\Entity\Page - it have a OneToOne to Content > - AppBundle\Entity\Content\Content (abstract) > - AppBundle\Entity\Content\ContentText extends Content > - AppBundle\Entity\Content\ContentImage extends Content - it have a > ManyToOne to media-bundle's "Media" > - AppBundle\Entity\Content\ContentVideo extends Content - it have a > ManyToOne to media-bundle's "Media" > > *My admin classes:* > > - AppBundle\Admin\PageAdmin - for AppBundle\Entity\Page > > > - AppBundle\Admin\ContentAdmin - for AppBundle\Entity\Content\Content > - from configureFormFields it loads the needed fields for each "Content" > subclass (text for text, and sonata_type_model_list for medias) > > > > *Details of the error:* > > *From ContentAdmin* > Everything works fine, and I'm able to edit everything, using > sonata_type_model_list > > *From PageAdmin* > When I load the related (OneToOne) Content using *sonata_type_admin*: > > - if the content related is a ContentText , it works fine. (Actually, > I've more Content subclasses similar to ContentText, and it works > fine. But none of them have ManyToOne fields) > - If the content related is a ContentImage or ContentVideo (both > loaded with *sonata_type_model_list*), *it fires the error:* > > Impossible to invoke a method ("id") on a null variable in > SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig at line 60 > > > *My versions:* > > > - sonata-project/admin-bundle 2.3.10 > - sonata-project/doctrine-orm-admin-bundle 2.3.4 > - sonata-project/media-bundle 2.3.4 > > > I've read similar errors on github, but I'm not sure if they are related. > Just for your info, I copy them: > https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/222 > https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/252 > > Thanks!! > > -- You received this message because you are subscribed to the Google Groups "sonata-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sonata-users/3c433ba4-7727-45d8-b9d0-bc28e6ddcde7%40googlegroups.com.
