2017-06-28 47 views
0

我有一对多的关系,它是具有很多费率的货币。所以我将它们定义为我从人工阅读:Symfony3和Doctrine中的OneToMay关系

/** 
* @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; 
    } 
} 

但似乎我不能只分配货币模型属性$这个 - >货币,因为学说认为这是一些原始如int,只是在查询中插入{}。

Object of class AppBundle\Entity\Currency could not be converted to string 

如果我改变字段currency_id从吸气和返回INT - 这是很好,但我怎么可能在这种情况下,相关的货币模型(我的意思是$速率 - > getCurrency() - >东西)?当然,我可以实现Currency :: __ toString,但看起来像可怕的想法。

回答

3

删除@ORM\Column注释:

* @ORM\Column(name="currency_id", type="integer") 

学说会弄清楚什么应该是referencedColumnName此列筑底中@ORM\JoinColumn声明的类型。

+0

非常感谢。你救了我的一天=) –