我有一对多的关系,这是一种有很多利率的货币。因此,当我阅读手册时,我定义了它们:
/**
* @ORM\Table(name="currency")
* @ORM\Entity
*/
class Currency{}
/**
* @ORM\Table(name="rate")
* @ORM\Entity
*/
class Rate
{
/**
* @ORM\Column(name="currency_id", type="integer")
* @ORM\ManyToOne(targetEntity="Currency", inversedBy="rate")
* @ORM\JoinColumn(name="currency_id", referencedColumnName="id")
*/
private $currency;
/**
* @param Currency $currency
* @return Rate
*/
public function setCurrency(Currency $currency) : Rate
{
$this->currency = $currency;
return $this;
}
/**
* @return Currency
*/
public function getCurrency() : Currency
{
return $this->currency;
}
}但是,我似乎不能仅仅将货币模型分配给属性$this->currency,,因为Doctrine认为它像int一样简单,只是在查询中插入{}。
Object of class AppBundle\Entity\Currency could not be converted to string如果我将字段更改为currency_id并从getter返回int --这很好,但在这种情况下,我如何能够使用相关的货币模型(我指的是)当然,我可以实现Currency::__toString,但是看起来很糟糕。
发布于 2017-06-28 09:37:02
删除@ORM\Column注释:
* @ORM\Column(name="currency_id", type="integer")原则将根据referencedColumnName在@ORM\JoinColumn中声明的内容来确定本专栏的类型。
https://stackoverflow.com/questions/44798765
复制相似问题