INSERT INTO features_values (`feature_id`, `name`) (
SELECT f.id, 'Пропан'
FROM features f
WHERE f.name = 'Заправка' AND f.`type` = 'enum'
);
INSERT INTO features_values (`feature_id`, `name`) (
SELECT f.id, 'ДТ'
FROM features f
WHERE f.name = 'Заправка' AND f.`type` = 'enum'
);
Сделайте один запрос..
INSERT IGNORE INTO features_values (`feature_id`, `name`) (
SELECT DISTINCT f.id, :feature_value_name
FROM features f
WHERE f.name = :feature_name AND f.`type` = :feature_type
);
{
"feature_id": 36,
"cloning": true,
"type": "enum",
"name": "Заправка",
"value": [
"Аи-92",
"Аи-95",
"Пропан"
]
}
INSERT IGNORE INTO features_values (`feature_id`, `name`) (
SELECT DISTINCT f.id, :feature_value_name
FROM features f
WHERE f.name = :feature_name AND f.`type` = :feature_type
);
/**
* @param string $feature_name
* @param string $feature_value_name
* @throws DBALException
*/
public function cloning(string $feature_name, string $feature_value_name)
{
$conn = $this->getEntityManager()->getConnection();
$sql = "
INSERT IGNORE INTO features_values (`feature_id`, `name`) (
SELECT DISTINCT f.id, :feature_value_name
FROM features f
WHERE f.name = :feature_name AND f.`type` = :feature_type
);
";
$stmt = $conn->prepare($sql);
$stmt->execute([
"feature_type" => EnumFeatureType::ENUM_TYPE,
"feature_name" => $feature_name,
"feature_value_name" => $feature_value_name
]);
}
Так как это тоже приводит к потере производительности.