update for warehouse
This commit is contained in:
@@ -19,7 +19,15 @@ class TTCrudBaseModel {
|
||||
$sqlValues = [];
|
||||
foreach ($data as $field => $value) {
|
||||
if (!property_exists(get_called_class(), $field)) {
|
||||
throw new Exception("Field $field does not exist in " . get_called_class());
|
||||
die(json_encode([
|
||||
"status" => "error",
|
||||
"error" => "Field $field does not exist in " . get_called_class(),
|
||||
"data" => $data
|
||||
]));
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = json_encode($value);
|
||||
}
|
||||
|
||||
$sqlValues[] = $value === null ? 'NULL' : "'" . $db->real_escape_string($value) . "'";
|
||||
@@ -62,7 +70,12 @@ class TTCrudBaseModel {
|
||||
}
|
||||
|
||||
if (!isset($data[$field])) {
|
||||
throw new Exception("Required field $field is missing in data array");
|
||||
http_response_code(500);
|
||||
die(json_encode([
|
||||
"status" => "error",
|
||||
"error" => "Required field $field is missing in data array",
|
||||
"data" => $data
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +117,7 @@ class TTCrudBaseModel {
|
||||
$sql = "WHERE 1=1";
|
||||
foreach ($filter as $key => $value) {
|
||||
if (!property_exists(get_called_class(), $key)) {
|
||||
http_response_code(500);
|
||||
throw new Exception("Field $key does not exist in " . get_called_class());
|
||||
}
|
||||
$sql .= Helper::generateFilterCondition($value, $key, gettype($value) === "integer");
|
||||
@@ -161,6 +175,10 @@ class TTCrudBaseModel {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = json_encode($value);
|
||||
}
|
||||
|
||||
$values[] = $value === null ? "`$field` = NULL" : "`$field` = '" . $db->real_escape_string($value) . "'";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user