Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 在学说中对外键的独特限制_Symfony_Doctrine Orm - Fatal编程技术网

Symfony 在学说中对外键的独特限制

Symfony 在学说中对外键的独特限制,symfony,doctrine-orm,Symfony,Doctrine Orm,有没有办法在原则中添加外键约束?这是我对Symfony 3.3中实体的配置。 条令:方案:验证命令给出的回答类似于“在“关税”表中没有名为“产品”的列” 您需要引用列的名称(而不是原则使用的关系的名称)。默认情况下,条令将用\u id作为关系名称的后缀,但您可以配置连接列的确切名称,如以下配置示例所示: 'Your\Entity\ProductVariant': manyToOne: image: targetEntity: 'Your\Entity\Product\Im

有没有办法在原则中添加外键约束?这是我对Symfony 3.3中实体的配置。 条令:方案:验证命令给出的回答类似于“在“关税”表中没有名为“产品”的列”


您需要引用列的名称(而不是原则使用的关系的名称)。默认情况下,条令将用
\u 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'

您可以尝试使用注释,它更清晰、更简单。谢谢您的回答。那么我将如何通过注释来实现这一点呢?您可以尝试使用
数组中的
product\u id
timeunit\u 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'