mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-18 17:28:41 +00:00
Fixing minor bugs for insert, such as accessibility and query building in loops.
This commit is contained in:
parent
fdef759d37
commit
e247c6a627
|
|
@ -249,7 +249,9 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
|
||||
foreach ($properties as $property) {
|
||||
foreach (static::$columns as $key => $column) {
|
||||
if ($column['internal'] === $property) {
|
||||
if ($column['internal'] === $property->getName()) {
|
||||
$property->setAccessible(true);
|
||||
|
||||
$value = $property->getValue($obj);
|
||||
|
||||
if ($column['type'] === 'DateTime') {
|
||||
|
|
@ -257,7 +259,9 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
}
|
||||
|
||||
$query->insert($column['name'])
|
||||
->values($value);
|
||||
->value($value);
|
||||
|
||||
// todo: do i have to reverse the accessibility or is there no risk involved here?
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -385,7 +389,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
->from(static::$table)
|
||||
->limit(1);
|
||||
|
||||
if(isset(static::$createdAt)) {
|
||||
if (isset(static::$createdAt)) {
|
||||
$query->orderBy(static::$table . '.' . static::$columns[static::$createdAt]['name'], 'DESC');
|
||||
} else {
|
||||
$query->orderBy(static::$table . '.' . static::$columns[static::$primaryField]['name'], 'DESC');
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
namespace phpOMS\DataStorage\Database\Query;
|
||||
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Database\Query;
|
||||
|
||||
/**
|
||||
* Database query builder.
|
||||
|
|
@ -174,7 +175,7 @@ class Builder
|
|||
* @var QueryType
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = null;
|
||||
protected $type = QueryType::INSERT;
|
||||
|
||||
protected $unionLimit = null;
|
||||
|
||||
|
|
@ -792,6 +793,26 @@ class Builder
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Values to insert.
|
||||
*
|
||||
* @param mixed $value Values
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function value($value) : Builder
|
||||
{
|
||||
end($this->values);
|
||||
$key = key($this->values);
|
||||
$this->values[$key][] = $value;
|
||||
reset($this->values);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function update() : Builder
|
||||
{
|
||||
$this->type = QueryType::UPDATE;
|
||||
|
|
@ -877,7 +898,8 @@ class Builder
|
|||
return $this->type;
|
||||
}
|
||||
|
||||
public function merge($query) : Builder {
|
||||
public function merge($query) : Builder
|
||||
{
|
||||
return clone($this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,10 +169,10 @@ class Grammar extends \phpOMS\DataStorage\Database\Grammar
|
|||
$components = $this->insertComponents;
|
||||
break;
|
||||
case QueryType::UPDATE:
|
||||
$components = null;
|
||||
$components = [];
|
||||
break;
|
||||
case QueryType::DELETE:
|
||||
$components = null;
|
||||
$components = [];
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown query type.');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user