我有一个与该实体CreditCard
相关的User
实体:
/**
* CreditCard
*
* @ORM\Table(name="credit_card")
* @ORM\Entity
*/
class CreditCard
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="value", type="string")
*/
protected $value;
/**
* @var User
*
* @ORM\OneToOne(targetEntity="User", mappedBy="creditCard")
*/
protected $user;
}
当我序列化CreditCard
实体时,它还会user
使用密码等用户数据序列化字段。
{{ creditCard|serialize }}
给出:
{"id":70,"value":"1721742","user":{"id":1,"username":"1721742","email":"hsz@domain.tld","enabled":true,"salt":"xxx","password":"yyy","last_login":"2013-05-27T09:18:30+0200","locked":false, ..... } }
如何防止它只允许序列化id
实体?username
User