2017-06-28 10 views
0

私は1対多の関係を持っています。多くのレートの通貨です。だから私は、マニュアルから読み取るように私はそれらを定義します。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型のようないくつかの原始的だと思うので、私はちょうど財産ます$ this->通貨に通貨モデルを割り当てることができないようだ、とだけ{}をクエリに挿入します。 > -

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") 

Doctrineは@ORM\JoinColumnで宣言さreferencedColumnNameに、このコラムの基点のタイプがどうあるべきか、それを把握します。

+0

ありがとうございました。あなたは私の日を救った=) –

関連する問題