title: Exclude some attributes from relational entity RestBundle Symfony2
body: <p>I want to exclude some attributes when I return an object with relations.</p>
  
  <p>For example, I have an entity Users and Album and I just want to expose the username when I get a list of Album.</p>
  
  <p>Is it possible ?</p>
  
  <p>Here is my Album entity :</p>
  
  <pre><code>&lt;?php
  
  namespace Billion\AlbumBundle\Entity;
  
  use Billion\AlbumBundle\Entity\Media;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Album
   *
   * @ORM\Table()
   * @ORM\Entity
   */
  class Album
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=255)
       */
      private $name;
  
      /**
       * @var string
       *
       * @ORM\Column(name="longitude", type="string", length=255, nullable=true)
       */
      private $longitude;
  
      /**
       * @var string
       *
       * @ORM\Column(name="latitude", type="string", length=255, nullable=true)
       */
      private $latitude;
  
      /**
       * @ORM\OneToMany(targetEntity="Billion\AlbumBundle\Entity\Media", mappedBy="album")
       **/
      private $medias;
  
      /**
       * @ORM\OneToOne(targetEntity="Billion\UserBundle\Entity\Users")
       * @ORM\JoinColumn(name="owner_id", referencedColumnName="id", nullable=false)
       */
      private $owner;
  
      /**
       * @ORM\OneToOne(targetEntity="Billion\SecurityBundle\Entity\Visibility")
       * @ORM\JoinColumn(name="visibility_id", referencedColumnName="id", nullable=false)
       */
      private $visibility;
  
  
      /**
       * Constructor
       */
      public function __construct()
      {
          $this-&gt;medias = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
  }
  </code></pre>
  
  <p>And my Users entity :
  
  
  <pre><code>namespace Billion\UserBundle\Entity;
  
  use FOS\UserBundle\Model\User as BaseUser;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Users
   *
   * @ORM\Table()
   * @ORM\Entity
   */
  class Users extends BaseUser
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @ORM\OneToMany(targetEntity="Billion\UserBundle\Entity\Friends", mappedBy="myFriends")
       **/
      private $myFriends;
  
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
      /**
       * Constructor
       */
      public function __construct()
      {
          $this-&gt;myFriends = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
      /**
       * Add myFriends
       *
       * @param \Billion\UserBundle\Entity\Friends $myFriends
       * @return Users
       */
      public function addMyFriend(\Billion\UserBundle\Entity\Friends $myFriends)
      {
          $this-&gt;myFriends[] = $myFriends;
  
          return $this;
      }
  
      /**
       * Remove myFriends
       *
       * @param \Billion\UserBundle\Entity\Friends $myFriends
       */
      public function removeMyFriend(\Billion\UserBundle\Entity\Friends $myFriends)
      {
          $this-&gt;myFriends-&gt;removeElement($myFriends);
      }
  
      /**
       * Get myFriends
       *
       * @return \Doctrine\Common\Collections\Collection 
       */
      public function getMyFriends()
      {
          return $this-&gt;myFriends;
      }
  }
  </code></pre>
  
  <p>And here is my exclusion policy for Users :</p>
  
  <pre><code>Billion\AlbumBundle\Entity\Album:
      exclusion_policy: ALL
      properties:
          name:
              expose: true
          longitude:
              expose: true
          latitude:
              expose: true
          visibility:
              expose: true
          medias:
              expose: true
          owner:
              expose: true
  </code></pre>
  
  <p>Thank you for any help !</p>