symfony - Associated entities with onDelete: CASCADE option and both soft-deleteable not working -


everyone!

i have 2 associated entities(user,picture) cascade="remove" option , both soft-deleteable

when use softdelete delete user, should put pictures deleted.and it's not working.

without softdelete works perfect.

can me solve problem?

my code:

picture.orm.yml

leo\testbundle\entity\picture: type: entity repositoryclass: leo\testbundle\entity\picturerepository table: null manytoone:    user:        targetentity: user        inversedby: pictures        joincolumn:            name: user_id            referencedcolumnname: id            ondelete: cascade gedmo:     soft_deleteable:       field_name: deletedat fields:     id:         type: integer         id: true         generator:             strategy: auto     name:         type: string         length: 255     path:         type: string         length: 255     deletedat:         type: datetime         nullable: true 

user.orm.yml:

leo\testbundle\entity\user: type: entity table: null repositoryclass: leo\testbundle\entity\userrepository onetomany:     pictures:         targetentity: picture         mappedby: user gedmo:     soft_deleteable:       field_name: deletedat fields:     id:         type: integer         id: true         generator:             strategy: auto     username:         type: string         length: 255     email:         type: string         length: 255     password:         type: string         length: 255     sex:         type: integer     bloodtype:         type: string         length: 10     birthday:         type: date     pr:         type: text     salt:         type: string         length: 255     deletedat:         type: datetime         nullable: true lifecyclecallbacks: {  } 

app/config/config.yml

doctrine:     orm:         auto_generate_proxy_classes: %kernel.debug%         auto_mapping: true         filters:             softdeleteable:                 class: gedmo\softdeleteable\filter\softdeleteablefilter                 enabled: true 

action

public function deleteaction() {     $token = $this->getrequest()->get('token');     if (! $this->get('form.csrf_provider')->iscsrftokenvalid('user_list', $token)) {         //todo use setflashbag         $this->get('session')->setflash('notice', 'woops! token invalid!');         return $this->redirect('user_list');     }     //$em = $this->getdoctrine()->getentitymanager();     $em = $this->getdoctrine()->getmanager();     $user = $this->getuser();     $pictures = $user->getpictures();     $em->remove($user);     /* foreach( $pictures $p ){         unlink($p->getabsolutepath());     } */     $em->flush();     $this->get('security.context')->settoken(null);     $this->getrequest()          ->getsession()          ->invalidate();     return $this->redirect($this->generateurl('leo_test_homepage')); } 

`

ok, problem found out.is carelessness.

leo\testbundle\entity\picture: type: entity repositoryclass: leo\testbundle\entity\picturerepository table: null manytoone:    user:        targetentity: user        inversedby: pictures        joincolumn:            name: user_id            referencedcolumnname: id            #**comment out line of code**            #ondelete: cascade gedmo:     soft_deleteable:       field_name: deletedat 

user entity

leo\testbundle\entity\user: type: entity table: null repositoryclass: leo\testbundle\entity\userrepository onetomany:     pictures:         targetentity: picture         mappedby: user         # add cascade option here         cascade: [persist, remove] gedmo:     soft_deleteable:       field_name: deletedat 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -