Allow obj relations

This commit is contained in:
Dennis Eichhorn 2020-02-02 15:49:59 +01:00
parent 3713e3fc11
commit 85b8bbec04
2 changed files with 8 additions and 3 deletions

View File

@ -678,7 +678,7 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private static function getObjectId(object $obj, \ReflectionClass $refClass = null) public static function getObjectId(object $obj, \ReflectionClass $refClass = null)
{ {
$refClass = $refClass ?? new \ReflectionClass($obj); $refClass = $refClass ?? new \ReflectionClass($obj);
$refProp = $refClass->getProperty(static::$columns[static::$primaryField]['internal']); $refProp = $refClass->getProperty(static::$columns[static::$primaryField]['internal']);
@ -1007,7 +1007,7 @@ class DataMapperAbstract implements DataMapperInterface
* In case of a many to many relation the relation has to be stored in a relation table * In case of a many to many relation the relation has to be stored in a relation table
* *
* @param string $propertyName Property name to initialize * @param string $propertyName Property name to initialize
* @param array $objsIds Object ids to insert * @param array $objsIds Object ids to insert (can also be the object itself)
* @param mixed $objId Model to reference * @param mixed $objId Model to reference
* *
* @return void * @return void
@ -1024,6 +1024,11 @@ class DataMapperAbstract implements DataMapperInterface
->insert(static::$hasMany[$propertyName]['src'], static::$hasMany[$propertyName]['dst']); ->insert(static::$hasMany[$propertyName]['src'], static::$hasMany[$propertyName]['dst']);
foreach ($objsIds as $key => $src) { foreach ($objsIds as $key => $src) {
if (\is_object($src)) {
$mapper = \get_class($src) . 'Mapper';
$src = $mapper::getObjectId($src);
}
$relQuery->values($src, $objId); $relQuery->values($src, $objId);
} }

View File

@ -169,7 +169,7 @@ final class Request extends RequestAbstract
\parse_str($content, $temp); \parse_str($content, $temp);
$this->data += $temp; $this->data += $temp;
} elseif (\stripos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false) { } elseif (\stripos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false) {
$content = file_get_contents('php://input'); $content = \file_get_contents('php://input');
$stream = \fopen('php://input', 'r'); $stream = \fopen('php://input', 'r');
$partInfo = null; $partInfo = null;
$boundary = null; $boundary = null;