Compare commits

...

3 Commits

View File

@@ -31,7 +31,7 @@ class Model
/** /**
* @var array Attributes to ignore when saving to the database. * @var array Attributes to ignore when saving to the database.
*/ */
protected static array $dbIgnoreSave = ['id']; protected static array $dbIgnoreSave = [];
/** /**
* @var array Attributes that should be explicitly saved, even if private/protected. * @var array Attributes that should be explicitly saved, even if private/protected.
@@ -480,12 +480,8 @@ class Model
$set = []; $set = [];
foreach ($atts as $key => $value) { foreach ($atts as $key => $value) {
if ($value !== null) { $set[] = "$key=:$key";
$set[] = "$key=:$key"; static::$dbQueryVariables[':' . $key] = $value;
static::$dbQueryVariables[':' . $key] = $value;
} else {
$set[] = "$key=NULL";
}
} }
$table = static::table(); $table = static::table();
@@ -511,11 +507,9 @@ class Model
static::$dbQueryVariables = []; static::$dbQueryVariables = [];
foreach ($atts as $key => $value) { foreach ($atts as $key => $value) {
if (isset($value)) { $into[] = "$key";
$into[] = "$key"; $values[] = ":$key";
$values[] = ":$key"; static::$dbQueryVariables[":$key"] = $value;
static::$dbQueryVariables[":$key"] = $value;
}
} }
$table = static::table(); $table = static::table();
@@ -523,7 +517,7 @@ class Model
static::query($sql); static::query($sql);
$pk = static::$dbPrimaryKey; $pk = static::$dbPrimaryKey;
$this->$pk = $db->lastInsertId(); $this->$pk ??= $db->lastInsertId();
$this->markAsSaved(); $this->markAsSaved();
} }