This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » overriding delete method in a Many-to-Many relation
overriding delete method in a Many-to-Many relation [message #103137] Tue, 27 July 2010 16:47 Go to next message
noway  is currently offline noway
Messages: 5
Registered: August 2008
Junior Member
Hi all,

I've a problem with the delete method in my project.

here is my schema :

USER:
  columns:
    id:    {type: integer(7), primary: true, autoincrement: true}
    name:   {type: string(20), primary: false}
  relations:
    USER_SESSION:
      foreignAlias: Users
      local: id_user
      foreign: id_session
      refClass: USER_SESSION

SESSION:
  columns:
    id:    {type: integer(7), primary: true, autoincrement: true}
    name:   {type: string(20), primary: false}
  relations:
    USER_SESSION:
      foreignAlias: Sessions
      local: id_session
      foreign: id_user
      refClass: USER_SESSION

USER_SESSION:
  columns:
    id:    {type: integer(7), primary: true, autoincrement: true}
    id_user:   {type: integer(7)}
    id_session:   {type: integer(7)}
    deleted: {type: boolean, default: false}
  relations:
    SESSION:
      foreignAlias: Users 
      local: id_session
      foreign: id
      onDelete: CASCADE
    USER:
      foreignAlias: Sessions
      local: id_user
      foreign: id
      onDelete: CASCADE


I've created the modules to manipulate Users and Sessions tables and I'm able to add or remove Users, sessions and create or remove relations USER_SESSION (it add or delete the corresponding row). This is great !

The problem is that now I want that when I will update a user and cancel a subscription to a session I don't want to delete the row in the table USER_SESSION. I just want to update the boolean field of the row and set it to true when I remove the relation in my form.

Anybody know how to override the delete method to not delete the many to many relation when calling the executeUpdate ?

I've tried to override preDelete and postDelete but it continues to remove the entry from the table.


Thanks !
regards,
Pierre.
Re: overriding delete method in a Many-to-Many relation [message #103176 is a reply to message #103137 ] Wed, 28 July 2010 11:48 Go to previous message
tkoomzaaskz  is currently offline tkoomzaaskz
Messages: 101
Registered: February 2008
Location: Poland
Senior Member
preDelete and postDelete is wrong choice to solve your problem, since those methods will be called before/after deleting UserSession record, which means that THIS RECORD WILL BE DELETED no matter how much you want to rescue it Smile I'd suggest you to change a form widget. Probably, you use some standard many-to-many relationship widgets in your User and Session admin modules and their standard behaviour is that removing connections between User and Session means deleting UserSession record. I'm NOT SURE, but I'd try to change the form widget.


symfony-world blog
Previous Topic:doctrine execute only returns one row
Next Topic:sf_environment setting gets lost if all unit tests are executed
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software