Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1.  
  2. class Nekretnina extends CActiveRecord
  3. {
  4.     .......
  5.  
  6.     public function relations()
  7.     {
  8.         return array(
  9.             .....
  10.  
  11.             'slike' => array(self::HAS_MANY, 'Slika', 'id_nekretnine'),
  12.         );
  13.     }
  14.  
  15.         protected function beforeDelete()
  16.     {
  17.         Slika::model()->deleteAll('id_nekretnine='.$this->id);
  18.                 return parent::beforeDelete();
  19.     }
  20. }
  21.  
  22. class Slika extends CActiveRecord
  23. {
  24.     ........
  25.  
  26.         protected function beforeDelete(){
  27.             unlink(Yii::app()->basePath.'/../images/'.$this->putanja);
  28.             unlink(Yii::app()->basePath.'/../images/.tmb/tmb_'.$this->putanja);
  29.             return parent::beforeDelete();
  30.         }
  31. }
  32.  
  33. "Nekretnina" means real estate, and "Slika" means picture in Serbian.
  34.  
  35. When I call delete method from NekretninaController: It deletes all picture(slika) rows that are asociated with that real estate(nekretnina) and then deletes real estate(nekretnina).
  36.  
  37. Real estate's(Nekretnina) beforeDelete is called, but picture's(slika) beforeDelete isn't!
  38.  
  39. When I call delete action from SlikaController, beforeDelete is called.
  40.  
  41. How to activate beforeDelete of Slika model from NekretninaController ?
  42.  
  43. Thank you
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement