douxiajia6720 2013-10-04 14:02
浏览 15

不是实体的Doctrine store对象值

how can I solve this problem. An entity class aggregates an object. Its value should be stored in the database. I have the following entity:

<?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;
}

?>

If I want to store a price in the database, how can I do that? This is obviously not working:

<?php

$price = new Price();
$price->setAmount(19.99);

$product = new Product();
$product->setPrice($price);

$em->persist($product);
$em->flush();

?>

Do I have to implement a new mapping type?

  • 写回答

3条回答 默认 最新

  • doushupu2521 2013-10-04 14:32
    关注

    You can define Custom Mapping Types

    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM