private function cleanUpRecords($newValues) { if (!$this->parent->exists()) { return; } $newIds = []; foreach ($newValues as $nv) { if (isset($nv['id']) && $nv['id'] != '') { $newIds[] = Entity::getInstance()->getDatabase()->id($nv['id']); } } $attrValues = $this->getValue(); foreach ($attrValues as $r) { if (!in_array($r->id, $newIds)) { $r->delete(); } } }
private function cleanUpRecords($newValues) { if (!$this->parent->exists()) { return; } $newIds = []; foreach ($newValues as $nv) { if (isset($nv['id']) && $nv['id'] != '') { $newIds[] = Entity::getInstance()->getDatabase()->id($nv['id']); } } $where = ['_id' => ['$nin' => $newIds]]; $where[$this->relatedAttribute] = $this->parent->id; $toRemove = call_user_func_array([$this->entityClass, 'find'], [$where]); foreach ($toRemove as $r) { $r->delete(); } }