mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-08 05:18:40 +00:00
fix bug where nullmodels would break updating
This commit is contained in:
parent
1cb038fbc2
commit
452e541ecd
|
|
@ -445,7 +445,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
*/
|
*/
|
||||||
public static function create($obj, int $relations = RelationType::ALL)
|
public static function create($obj, int $relations = RelationType::ALL)
|
||||||
{
|
{
|
||||||
if (!isset($obj) || self::isNullModel($obj)) {
|
if (!isset($obj)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -453,6 +453,10 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
|
|
||||||
$refClass = new \ReflectionClass($obj);
|
$refClass = new \ReflectionClass($obj);
|
||||||
|
|
||||||
|
if (self::isNullModel($obj)) {
|
||||||
|
return self::getObjectId($obj, $refClass);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($id = self::getObjectId($obj, $refClass)) && static::$autoincrement) {
|
if (!empty($id = self::getObjectId($obj, $refClass)) && static::$autoincrement) {
|
||||||
$objId = $id;
|
$objId = $id;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1384,7 +1388,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
$query->update(static::$table)
|
$query->update(static::$table)
|
||||||
->where(static::$table . '.' . static::$primaryField, '=', $objId);
|
->where(static::$table . '.' . static::$primaryField, '=', $objId);
|
||||||
|
|
||||||
foreach (static::$columns as $key => $column) {
|
foreach (static::$columns as $column) {
|
||||||
$propertyName = \stripos($column['internal'], '/') !== false ? \explode('/', $column['internal'])[0] : $column['internal'];
|
$propertyName = \stripos($column['internal'], '/') !== false ? \explode('/', $column['internal'])[0] : $column['internal'];
|
||||||
if (isset(static::$hasMany[$propertyName])
|
if (isset(static::$hasMany[$propertyName])
|
||||||
|| $column['internal'] === static::$primaryField
|
|| $column['internal'] === static::$primaryField
|
||||||
|
|
@ -1519,7 +1523,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
*/
|
*/
|
||||||
public static function update($obj, int $relations = RelationType::ALL, int $depth = 3)
|
public static function update($obj, int $relations = RelationType::ALL, int $depth = 3)
|
||||||
{
|
{
|
||||||
if (!isset($obj) || self::isNullModel($obj)) {
|
if (!isset($obj)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1528,7 +1532,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
$refClass = new \ReflectionClass($obj);
|
$refClass = new \ReflectionClass($obj);
|
||||||
$objId = self::getObjectId($obj, $refClass);
|
$objId = self::getObjectId($obj, $refClass);
|
||||||
|
|
||||||
if ($depth < 1) {
|
if ($depth < 1 || self::isNullModel($obj)) {
|
||||||
return $objId;
|
return $objId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user