views:

28

answers:

2

Hi there!

I'm trying to build a model for content pages on my site, and i gave it a self reference named 'Related Page'. Now if i build my models and try to create a new page in the admin generator everything works fine. If i give the page a related page (or more) it works fine too, but if i go to the other page and try to edit the references symfony crashes:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2-2' for key 'PRIMARY'

I checked it in phpmyadmin and noticed that in the association table i have 2 ids (id1 and id2) and only the first id is a link:

(sorry I couldn't paste a link)

I tried to give an 'id' field to the association table so i had 3 fields (id, id1, id2), and i saw that when I update the relations in the other page (page2 to page1 and page2 to page3), it is creating the relations for that page (page2 to page1 and page3) and it is deleting the old relations (it was page1 to page2 and page1 to page3) and the final relations i have in the association table is page1 to page 1 (???) page 2 to page1 and page2 to page3.

My models are:

Page:
//...
      relations:
        RelatedPages:
          class: Page
          local: id1
          foreign: id2
          refClass: RelatedPage
          equal: true

RelatedPage:
  columns:
    id1:
      type: integer(4)
      primary: true
      unsigned: true
      notnull: true
    id2:
      type: integer(4)
      primary: true
      unsigned: true
      notnull: true

I'm using the symfony admin generator. Do I have to write some code to handle this, or am I doing something wrong?

I checked the doctrine documentation: link text

and it seems that everything is OK.

A: 

You need to add onDelete: CASCADE to the RelatedPages relation.

Here's the Symfony bug: http://trac.symfony-project.org/ticket/6273

cdmckay
Great thanks to your response, I will try that out today and I will share the results. e'
edem
It is not working. By the way I checked the link you provided and it is talking about JobeetCategory linking to JobeetJob. In my case I link the Page model to itself. So a Page can have many related pages which are Pages...and the SQL error is different, symfony tries to insert duplicate primary keys (the primary key in RelatedPage is composite). Do you have any ideas?
edem
A: 

Okay, it was some kind of Doctrine bug:

link text

The solution is there.

edem