hello i have try bellow code but my code not work properly
tags.forEach(function(value) {
var where1 = {};
var attr1 = ['id'];
attr1 = ['id'];
where1['name'] = value;
tagData['name'] = value;
tagModel.getTag(where1, attr1, function(code2,result2){
if(result2.length!=0) {
var quick_start_tagData={'quick_start_id' : result1['id'], 'tag_id' :result2[0]['id']}
quick_start_tagModel.saveData(quick_start_tagData, function(code2,result2){
});
console.log(quick_start_tagData);
} else {
tagModel.saveData(tagData, function(code2,result2) {});
}
});
});
problem is for loop iterate no.of data when i check value of that data into table if table have same value then get its id and insert and if not than add new record and get its id and insert into another table
but first select
query execute all time and than insert
query execute in loop
how to solve this issue
Query Execute like that way
Executing (default):
SELECT
id
FROMpxl_tag
ASpxl_tag
WHEREpxl_tag
.name
= 'a1';SELECT
id
FROMpxl_tag
ASpxl_tag
WHEREpxl_tag
.name
= 'a2';SELECT
id
FROMpxl_tag
ASpxl_tag
WHEREpxl_tag
.name
= 'a3';INSERT INTO
pxl_tag
(id
,name
,created_at
,updated_at
) VALUES (DEFAULT,'a3','2018-05-04 04:35:32','2018-05-04 04:35:32');INSERT INTO
pxl_tag
(id
,name
,created_at
,updated_at
) VALUES (DEFAULT,'a3','2018-05-04 04:35:32','2018-05-04 04:35:32');INSERT INTO
pxl_tag
(id
,name
,created_at
,updated_at
) VALUES (DEFAULT,'a3','2018-05-04 04:35:32','2018-05-04 04:35:32');
but i want first select
and insert
step by step