Skip to content

Commit 9c5794f

Browse files
committed
#21 update phpdoc
1 parent ea7a0e1 commit 9c5794f

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/Model/Behavior/InsertBehavior.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ public function insertOnce(Entity $entity, array $conditions = null)
7878
$insertData['modified'] = FrozenTime::now()->toDateTimeString();
7979
}
8080

81-
$escape = function ($content) {
82-
return is_null($content) ? 'NULL' : $content;
83-
};
84-
85-
$escapedInsertData = array_map($escape, $insertData);
8681
$fields = array_keys($insertData);
8782
$existsConditions = $conditions;
8883
if (is_null($existsConditions)) {
@@ -94,7 +89,7 @@ public function insertOnce(Entity $entity, array $conditions = null)
9489
->insert($fields)
9590
->epilog(
9691
$this
97-
->buildTmpTableSelectQuery($escapedInsertData)
92+
->buildTmpTableSelectQuery($insertData)
9893
->where(function (QueryExpression $exp) use ($existsConditions) {
9994
$query = $this->_table
10095
->find()
@@ -111,21 +106,21 @@ public function insertOnce(Entity $entity, array $conditions = null)
111106
/**
112107
* build tmp table's select query for insert select query
113108
*
114-
* @param array $escapedData escaped array data
109+
* @param array $insertData insert data
115110
* @throws LogicException select query is invalid
116111
* @return Query tmp table's select query
117112
*/
118-
private function buildTmpTableSelectQuery($escapedData)
113+
private function buildTmpTableSelectQuery($insertData)
119114
{
120115
$driver = $this->_table
121116
->getConnection()
122117
->getDriver();
123118
$schema = [];
124119
$binds = [];
125-
foreach ($escapedData as $key => $value) {
120+
foreach ($insertData as $key => $value) {
126121
$col = $driver->quoteIdentifier($key);
127-
if ($value === 'NULL') {
128-
$schema[] = "{$value} AS {$col}";
122+
if (is_null($value)) {
123+
$schema[] = "NULL AS {$col}";
129124
} else {
130125
$bindKey = ':' . strtolower(trim($key));
131126
$binds[$bindKey] = $value;
@@ -138,7 +133,7 @@ private function buildTmpTableSelectQuery($escapedData)
138133
]);
139134
$query = $tmpTable
140135
->find()
141-
->select(array_keys($escapedData))
136+
->select(array_keys($insertData))
142137
->from(
143138
sprintf('(SELECT %s) as tmp', implode(',', $schema))
144139
);

0 commit comments

Comments
 (0)