代码之家  ›  专栏  ›  技术社区  ›  johnwards

由于外键约束,无法删除对象

  •  0
  • johnwards  · 技术社区  · 15 年前

    这个很奇怪

    Contact:
      actAs: [Timestampable,SoftDelete]
      columns:
        first_name:  { type: string(255), notnull: true }
        second_name:  { type: string(255), notnull: true }
      relations:
        Forums:
          class: Forum
          refClass: ContactForum
          local: forum_id
          foreign: contact_id 
          foreignAlias: Contacts
        ContactForums:
          local: id
          foreign: contact_id
          class: ContactForum
          type: many
          foreignType: one
          cascade: [delete]
    
    Forum:
      actAs: [Timestampable,SoftDelete]
      columns:
        name:  { type: string(255), notnull: true }
      relations:
        ContactForums:
          class: ContactForum
          local: id
          foreign: forum_id
          type: many
          cascade: [delete]
    
    ContactForum:
      actAs: [Timestampable]
      columns:
        contact_id:  { type: integer, primary: true }
        forum_id: { type: integer, primary: true }
    

    如果我们把几个 Forum Contact 联系人 对象我们得到以下错误消息:

    无效的

    如果将SoftDelete添加到链接表中,那么delete将正常工作,SoftDelete也会正常工作。然而,我们不希望软删除的链接表,因为这意味着我们的主键不能正常工作。这是虫子吗?

    2 回复  |  直到 15 年前
        1
  •  1
  •   johnwards    15 年前

    这是一个理论错误。错误报告: http://www.doctrine-project.org/jira/browse/DC-795 有补丁要修。

        2
  •  0
  •   jdd    15 年前

    Contact:
      actAs: [Timestampable,SoftDelete]
      columns:
        first_name:  { type: string(255), notnull: true }
        second_name:  { type: string(255), notnull: true }
      relations:
        Forums:
          refClass: ContactForum
          local: contact_id
          foreign: forum_id 
          cascade: [delete]
    
    Forum:
      actAs: [Timestampable,SoftDelete]
      columns:
        name:  { type: string(255), notnull: true }
      relations:
        Contacts:
          refClass: ContactForum
          local: forum_id
          foreign: contact_id
          cascade: [delete]
    
    ContactForum:
      actAs: [Timestampable]
      columns:
        contact_id:  { type: integer, primary: true }
        forum_id: { type: integer, primary: true }
    

    在关系中,使用refClass指定类时, local foreign 意思是“其他类表中代表我的列”和“其他类表中代表其他类的列”。

    双重编辑:看。以下是正确运行和级联多对多关系所需的所有模式。您不需要定义两个关系来正确地级联删除。

    推荐文章