mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-10 05:58:42 +00:00
Prevent creating existing object in database
This commit is contained in:
parent
4e66128ea4
commit
23f31d359a
|
|
@ -346,8 +346,13 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
$refClass = new \ReflectionClass($obj);
|
$refClass = new \ReflectionClass($obj);
|
||||||
$objId = self::createModel($obj, $refClass);
|
|
||||||
self::setObjectId($refClass, $obj, $objId);
|
if (!empty($id = self::getObjectId($obj, $refClass))) {
|
||||||
|
$objId = $id;
|
||||||
|
} else {
|
||||||
|
$objId = self::createModel($obj, $refClass);
|
||||||
|
self::setObjectId($refClass, $obj, $objId);
|
||||||
|
}
|
||||||
|
|
||||||
if ($relations === RelationType::ALL) {
|
if ($relations === RelationType::ALL) {
|
||||||
self::createHasMany($refClass, $obj, $objId);
|
self::createHasMany($refClass, $obj, $objId);
|
||||||
|
|
@ -370,9 +375,13 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
{
|
{
|
||||||
self::extend(__CLASS__);
|
self::extend(__CLASS__);
|
||||||
|
|
||||||
$objId = self::createModelArray($obj);
|
if (!empty($id = $obj[static::$columns[static::$primaryField]['internal']])) {
|
||||||
\settype($objId, static::$columns[static::$primaryField]['type']);
|
$objId = $id;
|
||||||
$obj[static::$columns[static::$primaryField]['internal']] = $objId;
|
} else {
|
||||||
|
$objId = self::createModelArray($obj);
|
||||||
|
\settype($objId, static::$columns[static::$primaryField]['type']);
|
||||||
|
$obj[static::$columns[static::$primaryField]['internal']] = $objId;
|
||||||
|
}
|
||||||
|
|
||||||
if ($relations === RelationType::ALL) {
|
if ($relations === RelationType::ALL) {
|
||||||
self::createHasManyArray($obj, $objId);
|
self::createHasManyArray($obj, $objId);
|
||||||
|
|
@ -1378,7 +1387,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
{
|
{
|
||||||
self::extend(__CLASS__);
|
self::extend(__CLASS__);
|
||||||
|
|
||||||
if (!isset($obj)) {
|
if (empty($obj)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user