В крайнем случае - инъекцией.
/* Вставка, которая не имеет отношения к следующей вставке */
INSERT IGNORE INTO `features` (`name`, `organization_id`) VALUES ('Авто', 17);
/* передать аргумент в LAST_INSERT_ID */
SELECT LAST_INSERT_ID(NULL);
/* В случае если не получится вставить, то в @feature_id будет null */
INSERT IGNORE INTO `features` (`name`, `organization_id`) VALUES ('Авто', 19);
SELECT LAST_INSERT_ID() INTO @feature_id;
/* если в @feature_id будет null, то вставить не получится */
INSERT IGNORE INTO `features_values` (`feature_id`, `name`) VALUES
(@feature_id, 'Tesla Model S'),
(@feature_id, 'Tesla Model X'),
(@feature_id, 'Tesla Cybertruck');
SELECT o0_.id AS id_0, o0_.name AS name_1, o0_.description AS description_2, o0_.post_code AS post_code_3, o0_.home AS home_4, o0_.site AS site_5, o0_.email AS email_6, o0_.schedule AS schedule_7, o0_.network_market AS network_market_8, o0_.rating AS rating_9, o0_.source AS source_10, o0_.services_str AS services_str_11, o0_.yandex_id AS yandex_id_12, f1_.id AS id_13, f1_.name AS name_14, f1_.type AS type_15, f1_.value AS value_16, g2_.id AS id_17, g2_.latitude AS latitude_18, g2_.longitude AS longitude_19, o0_.country_id AS country_id_20, o0_.city_id AS city_id_21, o0_.region_id AS region_id_22, o0_.street_id AS street_id_23, o0_.gps_id AS gps_id_24, f1_.organization_id AS organization_id_25 FROM organizations o0_ LEFT JOIN features f1_ ON o0_.id = f1_.organization_id AND (o0_.id = f1_.organization_id) LEFT JOIN gps g2_ ON o0_.gps_id = g2_.id LIMIT 5
{
"code": 0,
"count": 3,
"items": [
{
"id": "17",
"name": "Шиномонтаж у Палыча",
"description": "Наша компания занимается хернёй",
"post_code": 330688,
"home": null,
"site": null,
"email": "yellow@yellow.com",
"schedule": null,
"network_market": null,
"rating": "0.0",
"features": [
{
"id": "79",
"name": "Марка автомобиля",
"type": "enum",
"value": null
}
],
"gps": {
"id": "17",
"latitude": "1.00000000",
"longitude": "1.00000000"
}
},
{
"id": "18",
"name": "Шиномонтаж",
"description": "Наша компания занимается хернёй",
"post_code": 330688,
"home": null,
"site": null,
"email": "yellow@yellow.com",
"schedule": null,
"network_market": null,
"rating": "0.0",
"features": [
{
"id": "78",
"name": "Марка автомобиля",
"type": "enum",
"value": null
}
],
"gps": {
"id": "18",
"latitude": "2.00000000",
"longitude": "2.00000000"
}
},
{
"id": "19",
"name": "X-GOOD",
"description": "Наша компания занимается хернёй",
"post_code": 330688,
"home": null,
"site": null,
"email": "yellow@yellow.com",
"schedule": null,
"network_market": null,
"rating": "0.0",
"features": [
{
"id": "80",
"name": "Марка автомобиля",
"type": "enum",
"value": null
}
],
"gps": {
"id": "18",
"latitude": "2.00000000",
"longitude": "2.00000000"
}
}
]
}
{
"id": "80",
"name": "Марка автомобиля",
"type": "enum",
"value": null
}
{
"id": 78,
"type": "enum",
"name": "Марка автомобиля",
"value": [
{
"id": "191",
"name": "FORD"
},
{
"id": "196",
"name": "FORD-TRANZIT"
},
{
"id": "214",
"name": "FORD-CARGO"
}
]
}
{
"code": 0,
"count": 1,
"items": [
{
"id": "849059",
"name": "Комплекс Консалт",
"description": null,
"post_code": null,
"home": "38",
"site": "http://dolgsud.ru",
"email": "complexconsult@mail.ru",
"schedule": "пн–пт 10:00–18:00",
"network_market": null,
"rating": "0.0",
"features": [
{
"id": "4347353",
"name": "регистрация и ликвидация предприятий",
"type": "enum",
"value": null
}
],
"gps": {
"id": "849104",
"latitude": "59.89153000",
"longitude": "30.40895700"
}
}
]
}
/**
* @param string $feature_name
* @param string $feature_new_value
* @param array $array
* @throws DBALException
*/
public function cloning(string $feature_name, string $feature_new_value, array $array)
{
$conn = $this->getEntityManager()->getConnection();
$in = implode(", ", array_map(function ($item) {
return $item = "'$item'";
}, $array));
$sql = "
INSERT IGNORE INTO features_values (`feature_id`, `name`) (
SELECT f.id, :feature_new_value
FROM features f
JOIN features_values fv
ON f.id = fv.feature_id AND fv.name IN ($in)
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_new_value" => $feature_new_value
]);
}