2017-10-11 25 views
2

Doctrineの外部キーによる制約を追加する方法はありますか?これはSymfony 3.3のエンティティの設定です。 教義:スキーム:検証コマンドは私に「テーブルの上に名 『製品』は何のカラムがありません 『関税』」のような答えを与えるDoctrineの外部キーに対する一意の制約

Rg\ApiBundle\Entity\Tariff: 
    fields: 
     price: 
      type: float 
      column: price 
    manyToOne: 
     product: 
      targetEntity: Product 
      inversedBy: tariffs 
     timeunit: 
      targetEntity: Timeunit 
      inversedBy: tariffs 
    uniqueConstraints: 
     no_double_tariff_idx: 
      columns: 
       - product 
       - timeunit 
+0

あなたが代わりにアノテーションを使用しようとすることができ、それがより明確かつ簡単です。 –

+0

答えをありがとう。だから、どうすればアノテーションでそれをやることができますか? – kusrabs

+0

'列'配列に 'product_id'と' timeunit_id'を試すことができますか? – goto

答えて

0

あなたは、列の名前(ない名前を参照する必要があります教義によって使用される関係の)。デフォルトの教義によって_idと関係者の名前をサフィックスしますが、次の設定例に示すように、あなたが参加し、列の名前を正確に設定することができます。

'Your\Entity\ProductVariant': 
    manyToOne: 
    image: 
     targetEntity: 'Your\Entity\Product\Image' 
     joinColumn: 
     name: '`image_id`' 
     referencedColumnname: 'id' 
     nullable: false 
     options: 
      unique: false 
    color: 
     targetEntity: 'Your\Entity\Product\Color' 
     joinColumn: 
     name: '`color_id`' 
     referencedColumnname: 'id' 
     # [..] 
    uniqueConstraints: 
    only_one_image_of_same_product_color_idx: 
     columns: 
     - 'image_id' 
     - 'color_id' 
+0

ありがとうございました。私はそれをすぐにあなたがアドバイスした、それは動作します。 – kusrabs