【发布时间】:2015-07-27 07:57:22
【问题描述】:
如何在 jsonSerialize 方法中获取序列化的 cardPrices? id 是 OneToMany 与 CardPrice 的关系,但如何获得这个价格? 'price' => $this->getId()->getPriceNet() 不起作用。
CustomerCardSubtype.php
class CustomerCardSubtype implements \JsonSerializable
{
/**
* Primary key.
*
* @var int
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\OneToMany(targetEntity="CardPrice", mappedBy="customerCardSubtype")
*/
private $id;
/**
* @return array
*/
public function jsonSerialize()
{
return [
'id' => $this->getId(),
'description' => $this->getDescription(),
'name' => $this->getName()
];
}
CardPrice.php
class CardPrice implements \JsonSerializable
{
/**
* CustomerCardSubtype.
*
* @var CustomerCardSubtype
*
* @ORM\ManyToOne(targetEntity="CustomerCardSubtype")
* @ORM\JoinColumn(name="customer_card_subtype_id", referencedColumnName="id", nullable=false, onDelete="RESTRICT")
*/
private $customerCardSubtype;
/**
* Get priceNet.
*
* @return float
*/
public function getPriceNet()
{
return $this->priceNet;
}
【问题讨论】:
标签: symfony doctrine-orm