我怎么解决这个问题。一个实体类聚合一个对象。它的值应该存储在数据库中。我有以下实体:
<?php
class Price
{
private $_amount;
public function getAmount()
{
return $this->_amount;
}
public function setAmount($amount)
{
$this->_amount = $amount;
return $this;
}
}
/**
* Class Product
*
* @Entity
* @Table(name="product", options={"engine" = "NDBCLUSTER"})
*/
class Product
{
/**
* @Id
* @GeneratedValue
* @Column(name="id", type="integer")
* @var int
*/
private $_id;
/**
* @Column(name="price", type="decimal", precision=10, scale=2)
* @var Price
*/
private $_price;
}
?>
如果我想在数据库中存储价格,我该怎么做?这显然是行不通的:
<?php
$price = new Price();
$price->setAmount(19.99);
$product = new Product();
$product->setPrice($price);
$em->persist($product);
$em->flush();
?>
我必须实现新的映射类型吗?