title: SonataMediaBundle Usage with custom entities
body: <p>I'm using Symfony2 with Sonata bundles (Sonata-Admin and Sonata-Media) to develop my CMS project.</p>
  
  <p>I setup my admin classes for my custom bundle and it's working well. I need to attach images into my entities and view them in their user pages. But I have a problem with SonataMediaBundle to use in my custom entities. I'm trying to add a field to AdminController of my entity class and also create a manyToOne relationship in my entity definition.</p>
  
  <p>I never got it work and generally gives "Entity was not found" Exception (Doctrine\ORM\EntityNotFoundException class)</p>
  
  <p>I couldn't find an article except on <a href="http://sonata-project.org/bundles/media/master/doc/reference/installation.html#id1" rel="nofollow">SonataMedia Documentation</a> and couldn't solve this problem. Is anyone know a good article to read and understand the whole concept of SonataMedia Bundle?</p>
  
  <p>Some more information about my code is below:</p>
  
  <p>MyEntity.orm.yml</p>
  
  <pre><code>PRJ\Bundle\PRJBundle\Entity\MyEntity:
  type: entity
  table: my_table
  fields:
      id:
          id: true
          type: integer
          unsigned: false
          nullable: false
          generator:
              strategy: IDENTITY
  
  # Other fields eliminated
  
  manyToOne:
      picture:
          targetEntity: Application\Sonata\MediaBundle\Entity\Media
          joinColumns:
                  name: Picture_id
                  referencedColumnName: id
          orphanRemoval: false
  lifecycleCallbacks: {  }
  </code></pre>
  
  <p>Actually this code is working on both Admin panel and user pages but I couldn't make it work on admin pages when admin user is editing the record or entering new record.</p>
  
  <p>Also please correct me if I'm wrong, I'm assuming that I can generate an admin class for my custom entity that is attaching pictures. I'll add a field and define it as foreign key to media__media table in my database, and create necessary definitions on my Entities. At last I will be able to upload new pictures via SonataMediaBundle when creating new entities. Admin User will enters entity details and presses the upload button and chooses a picture, upload button works with SonataMedia bundle and uploads image to SonataMedia bundle's table also the new record will be created in my bundle's table and associated with newly created media.</p>
  
  <p>I hope I could described my problem well and thank you.</p>