Пример #1
0
 public function delete($filter, $subSdf = 'delete')
 {
     if ($subSdf && !is_array($subSdf)) {
         $subSdf = $this->getSubSdf($subSdf);
     }
     $allHas = (array) $this->has_parent;
     foreach ($allHas as $k => $v) {
         if (array_key_exists($k, $allHas)) {
             $subInfo = explode(':', $allHas[$k]);
             $modelInfo = explode('@', $subInfo[0]);
             $appId = $modelInfo[1] ? $modelInfo[1] : $this->app->app_id;
             $o = app::get($appId)->model($modelInfo[0]);
             $pkey = $o->_getPkey($this->table_name(), $subInfo[2], $this->app->app_id);
             $tFilter = $filter;
             if ($filter[$pkey['c']]) {
                 $tmp = array();
                 $tmp = $filter[$pkey['c']];
                 unset($tFilter[$pkey['c']]);
                 $tFilter[$pkey['p']] = $tmp;
             }
             $o->delete($tFilter, $v[1]);
         }
     }
     $allHas = array_merge((array) $this->has_many, (array) $this->has_one);
     foreach ((array) $subSdf as $k => $v) {
         if (array_key_exists($k, $allHas)) {
             // $subInfo = array();
             $subInfo = explode(':', $allHas[$k]);
             $modelInfo = explode('@', $subInfo[0]);
             $appId = $modelInfo[1] ? $modelInfo[1] : $this->app->app_id;
             $pkey = $this->_getPkey($modelInfo[0], $subInfo[2], $appId);
             $this->get_pk_list($filter);
             $tFilter = $filter;
             if ($filter[$pkey['p']]) {
                 $tmp = array();
                 $tmp = $filter[$pkey['p']];
                 unset($tFilter[$pkey['p']]);
                 $tFilter[$pkey['c']] = $tmp;
             }
             $o = app::get($appId)->model($modelInfo[0]);
             $o->delete($tFilter, $v[1]);
         }
     }
     if ($this->use_meta) {
         $pk = $this->get_pk_list($filter);
         foreach ($this->metaColumn as $col) {
             $obj_meta = new dbeav_meta($this->table_name(true), $col);
             $obj_meta->delete($pk);
         }
     }
     return parent::delete($filter);
 }
Пример #2
0
 /**
  * 删除数据
  *
  * 1. 删除当前model对应表
  * 2. 删除当前model对应关联 has_parent 表. has_parent表为反向关联表
  * 3. 删除当前model对应关联 has_many/has_one 表. has_many/has_one表为正向关联表
  *
  * @param  array
  * @param  array $filter
  * @return string $subSdf
  */
 public function delete($filter, $subSdf = 'delete')
 {
     if (!$filter) {
         return false;
     }
     // 获取所有 model has_parent 属性
     $this->deleteParent($filter);
     $this->deleteDepends($filter, $subSdf);
     return parent::delete($filter);
 }