mirror of
https://github.com/strapi/strapi.git
synced 2025-07-18 14:32:56 +00:00
Run sub queries for update and delete with joins
This commit is contained in:
parent
86a26da896
commit
bb1b3c2c6e
@ -191,6 +191,18 @@ const createQueryBuilder = (uid, db) => {
|
|||||||
this.select('*');
|
this.select('*');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (['delete', 'update'].includes(state.type) && state.joins.length > 0) {
|
||||||
|
this.select('id');
|
||||||
|
const subQB = this.getKnexQuery();
|
||||||
|
|
||||||
|
const nestedSubQuery = db.connection.select('id').from(subQB.as('subQuery'));
|
||||||
|
|
||||||
|
return db
|
||||||
|
.connection(tableName)
|
||||||
|
[state.type]()
|
||||||
|
.whereIn('id', nestedSubQuery);
|
||||||
|
}
|
||||||
|
|
||||||
switch (state.type) {
|
switch (state.type) {
|
||||||
case 'select': {
|
case 'select': {
|
||||||
if (state.select.length === 0) {
|
if (state.select.length === 0) {
|
||||||
@ -223,12 +235,14 @@ const createQueryBuilder = (uid, db) => {
|
|||||||
}
|
}
|
||||||
case 'update': {
|
case 'update': {
|
||||||
qb.update(state.data);
|
qb.update(state.data);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'delete': {
|
case 'delete': {
|
||||||
qb.del();
|
qb.del();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'truncate': {
|
||||||
|
db.truncate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user