代码之家  ›  专栏  ›  技术社区  ›  Sebastián Grignoli

条令关系在记录更新时丢失

  •  0
  • Sebastián Grignoli  · 技术社区  · 15 年前

    我在使用symfony和district,并且有几个多对多的关系可以很好地工作。

    但是有一个名为“document”的表,其中包含可以与多种内容相关的文档,并且有自己的管理部分。

    每当我更新一个文档时,它与其他表之间的所有关系都将丢失。

    我在网上搜索了一会儿,但找不到原因。

    你有没有经历过这样的事?我能做什么?

    这是模式,但MySQL中不存在约束。

    Document:
      actAs: [Timestampable]
      columns:
        title: string(255)
        filename: string(255)
        owner_id: integer
    Productar:
      actAs:
        Timestampable: ~
        I18n:
          fields: [title, tagline, intro, body]
      columns:
        title: string(255)
        tagline: clob
        intro: clob
        body: clob
        video: string(255)
        header_image: string(255)
        small_image: string(255)
      relations:
        Documents:
          class:        Document
          local:        productar_id
          foreign:      document_id
          type:         many
          refClass:     ProductarDocument
          onDelete:     SET NULL
    ProductarDocument:
      actAs: [Timestampable]
      columns:
        productar_id:
          type: integer
          fixed: false
          unsigned: false
          primary: true
          autoincrement: false
        document_id:
          type: integer
          fixed: false
          unsigned: false
          primary: true
          autoincrement: false
      relations:
        Productar:
          class:        Productar
          local:        productar_id
          foreign:      id
          onDelete:     SET NULL  # Also tried with CASCADE
        Document:
          class:        Document
          local:        document_id
          foreign:      id
          onDelete:     SET NULL  # Also tried with CASCADE
    
    2 回复  |  直到 15 年前
        1
  •  0
  •   Luis Junior    15 年前

    在phpmyadmin中,单击Relations并查找OnEdit操作

        2
  •  0
  •   Sebastián Grignoli    14 年前

    我发现了问题:

    在模型中存在关系之前,最初与/document/web模块一起生成的表单类。之后,添加了关系,并再次生成了表单和模型类,但没有添加Web模块(或表单的实际视图),因此表单类需要关系,但没有接收到关系,调用$Form->save()方法时,记录没有更新。

    我通过取消设置文档窗体类中的“productar_list”小部件和验证器来修复它。它不再被期待,也不再被保存。现在不更新关系了。