开发者

Doctrine relation lost on record update

开发者 https://www.devze.com 2023-01-07 19:05 出处:网络
I\'m using Symfony and Doctrine, and have several many-to-many relations that work fine. But there is a table called \"document\" that holds documents that can relate to several kind of contents, and

I'm using Symfony and Doctrine, and have several many-to-many relations that work fine.

But there is a table called "document" that holds documents that can relate to several kind of contents, and has an admin section of it's own.

Whenever I update a Document, every relation it had to the rest of the tables is lost.

I Googled it for a while but couldn't find the reason.

¿Have you ever experienced something like this? ¿What can I do?

This is the schema, but the const开发者_StackOverflowraints do not exist in 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


In phpmyadmin click on relations and look for onEdit actions


I found the problem:

The form classes where originally generated along with the /document/ web module before the relations existed in the model. Later, the relations were added and the form and model classes where generated again, but not the web module (or the actual view for the form), therefore the relations were expected, but not received, by the form class, and the record got updated without them when $form->save() method was called.

I fixed it by unsetting the "productar_list" widget and validator in the Document form class. It's no longer expected nor saved. It´s not updating the relations now.

0

精彩评论

暂无评论...
验证码 换一张
取 消