2015-07-12 77 views
0

我有2個實體。JMSSerializerBundle @expose關係,忽略其他實體策略

A StockItem和一個用戶。

他們看起來像這樣。

/** 
* StockItem 
* 
* @ORM\Table() 
* 
* @ORM\Entity(repositoryClass="IREnterprise\AppBundle\Entity\StockItemRepository") 
* @ORM\HasLifecycleCallbacks 
* 
* @ExclusionPolicy("all") 
* 
*/ 
class StockItem 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    * @Expose 
    */ 
    private $id; 

    /** 
    * @ORM\ManyToOne(targetEntity="IREnterprise\UserBundle\Entity\User", inversedBy="stockItems") 
    * @ORM\JoinColumn(name="user_id", referencedColumnName="id") 
    * @Expose 
    **/ 
    private $user; 
    ... 


/** 
* User 
* 
* @ORM\Table() 
* @ORM\Entity(repositoryClass="IREnterprise\UserBundle\Entity\UserRepository") 
* 
* @UniqueEntity("email") 
* @UniqueEntity("username") 
* 
* @ExclusionPolicy("all") 
* 
*/ 
class User extends BaseUser 
{ 

    const ROLE_CLIENT = 'ROLE_CLIENT'; 
    const ROLE_WORKER = 'ROLE_WORKER'; 

    /** 
    * @var integer 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="company", type="string", length=255) 
    * @Expose 
    */ 
    private $company; 
    .... 

正如你看到的,兩個實體擁有ExclusionPolicty一切,現在,如果我在StockItem執行查詢,我得到完整的用戶對象,用戶對象自己排除策略被忽略。

即使只有1個屬性「公司」在用戶實體中被暴露。

是否有可能@在關係中展示一個屬性?揭露關係時無需獲取整個對象。

回答