Пример #1
0
 /**
  * Delete the record from the table.
  * 
  * @return mixed
  */
 public function delete()
 {
     $this->beforeDelete();
     $data = $this->getModelData();
     $primaryKey = $this->getPrimaryKey();
     if (empty($data[$primaryKey])) {
         throw new RuntimeException("Cannot delete: missing value of primary key.");
     }
     $result = $this->definition->getStorage()->delete([$primaryKey => $data[$primaryKey]]);
     $this->afterDelete($result);
     return $result;
 }
Пример #2
0
 /**
  * Asserts the key is valid for the related model.
  */
 protected function assertValidForeignKey($key)
 {
     if (!in_array($key, $this->relatedDefinition->getColumnMap(), true)) {
         throw new InvalidArgumentException("Invalid key '{$key}' for '{$this->relatedDefinition->getName()}'");
     }
 }