1
votes

I'm facing this weird problem with Sonata media bundle.

Basically, I have an exercise that can have many pictures.

My mapping of Exercice (it's French language) is :

 /**
  * @ORM\OneToMany(targetEntity="Application\Sonata\MediaBundle\Entity\Media", mappedBy="exercice")
  */
    private $medias;

Then I go to Application/Sonara/MediaBundle/Entity/Media.php and add a field $exercice:

namespace Application\Sonata\MediaBundle\Entity;

use Sonata\MediaBundle\Entity\BaseMedia as BaseMedia;
use Doctrine\ORM\Mapping as ORM;


class Media extends BaseMedia
{
    /**
     * @var integer $id
     */
    protected $id;

    /**
     * @var
     * @ORM\ManyToOne(targetEntity="Acme\AcmeBundle\Entity\Exercice", inversedBy="medias")
     */
    private $exercice;

Weird things that happen :

  1. When I run : php app/console doctrine:generate:entities Application\Sonata\MediaBundle:Media I don't see any setter or getter for Exercice inside Media entity.
    1. I get this error in profiler :

The association Acme\AcmeBundle\Entity\Exercice#medias refers to the owning side field Application\Sonata\MediaBundle\Entity\Media#exercice which does not exist.

The relevant part of config :

orm: auto_generate_proxy_classes: "%kernel.debug%" auto_mapping: true mappings: ApplicationSonataMediaBundle: ~ SonataMediaBundle: ~

What am I doing wrong ?

Thanks

1

1 Answers

1
votes

Ok, found the solution. I had to modify the mapping from the xml file :

src/Application/Sonata/MediaBundle/Resources/config/doctrine/Media.orm.xml

I added :

<many-to-one field="exercice" inversed-by="medias" target-entity="Acme\AcmeBundle\Entity\Exercice" />

and it's working just fine.