-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[V4] QueryEngine - deleteMany not working when filter by nested entity. #11998
Comments
I reproduced it with sqlite too [Error: delete from `addresses` where (`t2`.`id` = 1) - SQLITE_ERROR: no such column: t2.id] {
errno: 1,
code: 'SQLITE_ERROR'
} And I found some evidences that it's WIP strapi/packages/core/content-manager/server/services/entity-manager.js Lines 202 to 207 in 0f9b692
strapi/packages/core/database/lib/entity-manager.js Lines 324 to 340 in e5ee7f0
|
Temporary workaroundassume that..
Examplelet addressItems;
try {
addressItems = await strapi
.query("api::address.address")
.findMany({ where: { category: { id: 1 } } });
} catch (e) {
console.error(e);
}
try {
for (const address of addressItems) {
await strapi
.query("api::address.address")
.delete({ where: { id: address.id } });
}
} catch (e) {
console.error(e);
} |
I would also love to get this fixed :-) |
This issue has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/find-and-filtering-entries-with-deletemany/21679/2 |
Just came across this, with oneToOne relation, strapi version 4.3.2 let tasks = await strapi.db.query("api::task.task").findMany({
where: {
parent: section.id,
},
}); Doesn't work: let tasks = await strapi.db.query("api::task.task").deleteMany({
where: {
parent: section.id,
},
}); Error message: error: delete from "tasks" using "tasks_parent_links" as "t1","sections" as "t2" where ("t2"."id" = $1) and "t0"."id" = "t1"."task_id" and "t1"."section_id" = "t2"."id" - missing FROM-clause entry for table "t0" |
i'm currently having this issue do you have any clue on how to solve that? |
I had exactly the same issue and I've managed to solve this by adding additional query I wanted to remove all all products (lamps) which are related to common family I know it's not perfect, but for this still I hope that they will fix it in near future
|
Just encountered this issue as well. Got it working with the code below. Seems like strapi just expects us to pass something in the id value in the where filter. So passing a query to match all ids in an array of numbers works just fine.
|
Just encountered this agian: {
"kind": "collectionType",
"attributes": {
"chat": {
"type": "relation",
"relation": "oneToOne",
"target": "api::chat.chat"
},
},
} message has one chat query: await strapi.db.query("api::message.message").deleteMany({ where: { chat: chatId }}); result [2022-11-14 21:07:03.662] error: delete from "messages" using "messages_chat_links" as "t1","chats" as "t2" where ("t2"."id" = $1) and "t0"."id" = "t1"."message_id" and "t1"."chat_id" = "t2"."id" - missing FROM-clause entry for table "t0"
error: delete from "messages" using "messages_chat_links" as "t1","chats" as "t2" where ("t2"."id" = $1) and "t0"."id" = "t1"."message_id" and "t1"."chat_id" = "t2"."id" - missing FROM-clause entry for table "t0" temporary fix, use find, Promise.all |
I have same issue with
|
this one is perfectly working.Here is what i have done exactly this person did: |
It's a nice workaround, but it's suboptimal in terms of performance. |
Any updates from strapi? |
not yet |
Unfortunately I experienced the bug yesterday |
Experienced this bug today, used @XanderD99 solution and it works |
I have the same issue with Postgresql, where I'm looking to update multiple addresses and filtering them by owner id ( FK to the user ). The issue has been open for close to 2 years already. Perhaps it's time to fix this? |
same issue, thanx @XanderD99, its working |
As per today, this bug is still there. It's been almost 2 years now. What is going on? Why hasn't this been fixed yet? |
Error still there in Not to mention, I encountered this bug because I couldn't fix another existing bug in Strapi: the deletion of relations associated with a deleted parent data item, which is the basis of any ORM. |
Same here, I adopt the solution by @XanderD99 for now but I think this is a serious issue that need to be fix as soon as possible. My case consists in a list of clinical records and some other stuff that need to be removed when the user delete the patient. |
Still occurs in the version 4.14.6 |
This is an important defect. Please pay attention to this. I created a helper function like this.
You can use it like this:
|
Any updates from strapi team? |
Hello all 👋 Sadly we cannot work on this issue at the moment because we are prioritizing other more critical issues. This one was defiend as low severity because a workaround exists for now. We are still a small team doing all our best to address the more urgent topics 🙏 If some of you are interested in contributing a fix let us know so we can guide you through the codebase 💯 |
Bug report
Describe the bug
When trying to deleteMany by the nested entity filtering, An error occurs.
Steps to reproduce the behavior
Expected behavior
All B filtered A will be deleted.
Screenshots
Code snippets
await strapi.query(A).deleteMany({ where: { B: { id: { $eq: params.id }, } } })
System
The text was updated successfully, but these errors were encountered: