在 Symfony 中使用 YAML 创建的关系(使用 Doctrine)不会填充到 MySQL 数据库中

发布于 2024-10-23 00:50:53 字数 1741 浏览 4 评论 0原文

我是 Symfony 的新手,尝试通过 build-model 然后 build-sql 创建数据库结构。

所有表都出现在数据库中,但是不会创建除简单一对多关系之外的关系。

例如,我有一个存储公司的表,它们可以是供应商或客户,我还有另一个存储客户/供应商关系的表。

Identifier:
  actAs: [Timestampable]
  tableName: identifier
  columns:
    id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
  relations:
    Suppliers:
      class: Identifier
      local: customer_id
      foreign: supplier_id
      refClass: CustomerSupplier
      foreignAlias: Customers
      onDelete: CASCADE
    Customers:
      class: Identifier
      local: supplier_id
      foreign: customer_id
      refClass: CustomerSupplier
      foreignAlias: Suppliers
      onDelete: CASCADE
CustomerSupplier:
  actAs: [Timestampable]
  tableName: customerSupplier
  columns:
    id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    customer_id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    supplier_id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false

也不会创建一对一关系:

IdentifierExtCompany:
  actAs: [Timestampable]
  tableName: identifierExtCompany
  columns:
    identifier_id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
  relations:
    Identifier:
      local: identifier_id
      foreign: id
      onDelete: CASCADE
      foreignType: one
      type: one

当我运行 build-sql 生成的 sql 请求时,所有这些关系都不会出现在数据库中。

你能帮我检测一下我的 yaml 文件中有什么问题吗?提前致谢

I am new to Symfony, trying to create a database structure through build-model then build-sql.

All the tables appear in the database however relations other than simple one-to-many relations are not created.

For instance I have a table storing companies, they can be both suppliers or customers and I have another table storing the customer/supplier relationship.

Identifier:
  actAs: [Timestampable]
  tableName: identifier
  columns:
    id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
  relations:
    Suppliers:
      class: Identifier
      local: customer_id
      foreign: supplier_id
      refClass: CustomerSupplier
      foreignAlias: Customers
      onDelete: CASCADE
    Customers:
      class: Identifier
      local: supplier_id
      foreign: customer_id
      refClass: CustomerSupplier
      foreignAlias: Suppliers
      onDelete: CASCADE
CustomerSupplier:
  actAs: [Timestampable]
  tableName: customerSupplier
  columns:
    id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    customer_id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    supplier_id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false

One-to-one relationships are not created either:

IdentifierExtCompany:
  actAs: [Timestampable]
  tableName: identifierExtCompany
  columns:
    identifier_id:
      type: integer(20)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
  relations:
    Identifier:
      local: identifier_id
      foreign: id
      onDelete: CASCADE
      foreignType: one
      type: one

All these relations don't appear in the database when I run the sql request generated by build-sql.

Could you help me to detect what is wrong in my yaml file? Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-10-30 00:50:53

例如,我有一个表存储公司,他们可以是供应商或客户,我还有另一个表存储客户/供应商关系。

似乎您也必须为 CustomerSupplier 定义关系:

relations:
  IdentifierAlias:
    class: Identifier
    local: identifier_id
    onDelete: CASCADE
  SupplierAlias:
    class: Supplier
    local: supplier_id
    onDelete: CASCADE

也不会创建一对一关系

尝试在关系中指定class属性并将其设置为Identifier

希望这有帮助。

For instance I have a table storing companies, they can be both suppliers or customers and I have another table storing the customer/supplier relationship.

Seems like you have to define relations for CustomerSupplier too:

relations:
  IdentifierAlias:
    class: Identifier
    local: identifier_id
    onDelete: CASCADE
  SupplierAlias:
    class: Supplier
    local: supplier_id
    onDelete: CASCADE

One-to-one relationships are not created either

Try to specify class attribute in relations and set it to Identifier.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文