Symfony1 在构建数据库时创建无法识别的表

Symfony1 在构建数据库时创建无法识别的表,symfony1,doctrine,Symfony1,Doctrine,我有下面的schema.yml Proposition: actAs: { Timestampable: ~ } columns: name: { type: string(255), notnull: true } slug: { type: string(255), notnull: true, unique: true } proposition_type_id: { type: integer, notnull: true } icon: { ty

我有下面的schema.yml

Proposition:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true }
    slug: { type: string(255), notnull: true, unique: true }
    proposition_type_id: { type: integer, notnull: true }
    icon: { type: string(255) }
    overview: { type: string(4000) }
    features: { type: string(4000) }
    benefits: { type: string(4000) }
    published: { type: boolean, notnull: true, default: 1 }
  relations:
    PropositionType: { onDelete: CASCADE, local: proposition_type_id, foreign: id }
    Products:
      class: Product
      refClass: PropositionProduct
      local: proposition_id
      foreign: product_id
      foreignAlias: PropositionProducts

PropositionType:
  columns:
    name: { type: string(255), notnull: true }

Review:
  actAs: { Timestampable: ~ }
  columns:
    proposition_id: { type: integer, notnull: true }
    review: { type: string(4000), notnull: true }
    name: { type: string(255), notnull: true }
    company: { type: string(255) }
    published: { type: boolean, notnull: true, default: 1 }
  relations:
    Proposition: { onDelete: CASCADE, local: proposition_id, foreign: id }

PropositionProduct:
  columns:
    proposition_id: { type: integer, primary: true }
    product_id: { type: integer, primary: true }
  relations:
    Proposition: { onDelete: CASCADE, local: proposition_id, foreign: id }
    Product: { onDelete: CASCADE, local: product_id, foreign: id }

Product:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true }
    slug: { type: string(255), notnull: true, unique: true }
    icon: { type: string(255) }
    ataglance: { type: string(4000) }
    idealfor: { type: string(4000) }
    details: { type: string(4000) }
    specsheet: { type: string(255) }
    chart: { type: string(255) }
    published: { type: boolean, notnull: true, default: 1 }
  relations:
    RelatedProducts:
      class: Product
      refClass: RelatedProduct
      local: product_id
      foreign: related_product_id
      foreignAlias: RelatedProducts

RelatedProduct:
  columns:
    product_id: { type: integer, primary: true }
    related_product_id: { type: integer, primary: true }
  relations:
    Product: { onDelete: CASCADE, local: product_id, foreign: id }
    Product: { onDelete: CASCADE, local: related_product_id, foreign: id }

Segment:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true }
    slug: { type: string(255), notnull: true, unique: true }
    published: { type: boolean, notnull: true, default: 1 }
  relations:
    Products:
      class: Product
      refClass: SegmentProduct
      local: segment_id
      foreign: product_id
      foreignAlias: SegmentProducts

SegmentProduct:
  columns:
    segment_id: { type: integer, primary: true }
    product_id: { type: integer, primary: true }
  relations:
    Segment: { onDelete: CASCADE, local: segment_id, foreign: id }
    Product: { onDelete: CASCADE, local: product_id, foreign: id }
我跑:

php symfony doctrine:build --all --and-load --no-confirmation
数据库建设成功

但是,为什么要创建一个proposition_段表呢

CREATE TABLE `proposition_segment` (
  `segment_id` bigint(20) NOT NULL DEFAULT '0',
  `product_id` bigint(20) NOT NULL DEFAULT '0',
  PRIMARY KEY (`segment_id`,`product_id`),
  KEY `proposition_segment_product_id_product_id` (`product_id`),
  CONSTRAINT `proposition_segment_product_id_product_id` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) ON DELETE CASCADE,
  CONSTRAINT `proposition_segment_segment_id_segment_id` FOREIGN KEY (`segment_id`) REFERENCES `segment` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
根据我的理解,我的方案应该通过SegmentProduct表详细说明细分市场和产品之间的多对多关系

同样,命题和乘积通过命题乘积表具有多对多关系

我不明白为什么条令要创建一个命题表。除此之外,该数据库看起来是正确的——它按照预期创建了表proposition\u product和segment\u product


当我通过Symfony生成的管理后端添加数据时,proposition_segment表仍然是空的,这增加了我对它创建错误的怀疑。

感谢GregFire的链接,今天早上在玩了几个小时后,我决定创建一个新的空白Symfony项目,并将我的scheme.yml加载到其中。在建立它之后,我得到了我想要的数据库结构!结果证明这个方案实际上是正确的,它一定是某个生成额外表的表单类?我会再做一些挖掘,看看到底发生了什么。我还根据您的建议更改了别名并创建了一个平等的嵌套关系-谢谢

编辑:


宾果!我在lib/model/中发现了一些不需要的类,整理这个文件夹修复了生成的额外表。我认为Doctrine只读取config/Doctrine/scheme.yml文件,但我猜它也会将您的模型读取到?-当然是这样,因为在所有示例中,它都显示了创建类的两种不同方式。我仍然不确定这些文件是什么时候生成的,但我会从现在开始关注我的模型。

感谢GregFire的链接,今天早上玩了几个小时后,我决定创建一个新的空白Symfony项目,并将我的scheme.yml加载到其中。在建立它之后,我得到了我想要的数据库结构!结果证明这个方案实际上是正确的,它一定是某个生成额外表的表单类?我会再做一些挖掘,看看到底发生了什么。我还根据您的建议更改了别名并创建了一个平等的嵌套关系-谢谢

编辑:


宾果!我在lib/model/中发现了一些不需要的类,整理这个文件夹修复了生成的额外表。我认为Doctrine只读取config/Doctrine/scheme.yml文件,但我猜它也会将您的模型读取到?-当然是这样,因为在所有示例中,它都显示了创建类的两种不同方式。我仍然不确定这些文件是什么时候生成的,但我会从现在开始关注我的模型。

这可能与您的问题无关,但我认为您用于分段类的产品关系的外来别名应该命名为分段,因为这将创建一个getSegments方法,该方法将返回段对象,而不是SegmentProducts对象。明智地选择你的名字,因为教义使用它们来推断你的模式中没有出现的东西,这有时会产生奇怪的事情。另一件事:你的模式中似乎有一个相等的嵌套关系:relatedProducts这里是它应该如何声明的:我不知道你所做的是否有严重的后果这可能与你的问题无关,但我认为,您用于段类的Products关系的foreignAlias应该命名为Segments,因为这将创建一个getSegments方法,该方法将返回段对象,而不是SegmentProducts对象。明智地选择你的名字,因为教义使用它们来推断你的模式中没有出现的东西,这有时会产生奇怪的事情。另一件事:您的模式中似乎有一个相等的嵌套关系:relatedProducts这里是它应该如何声明的:我不知道您所做的是否有严重的后果在每次重命名模型之后,您应该执行symfony原则:clean-model-files。在每次重命名模型之后您应该执行symfony原则:清理模型文件。