Describe the bug
Using a filter query to select rows for deletion fails if the filter query is a related field query (i.e. across a foreign key).
To Reproduce
from tortoise import Model, fields, run_async
from tortoise.contrib.test import init_memory_sqlite
class Device(Model):
device_id = fields.IntField(pk=True)
name = fields.CharField(max_length=16)
class LogMessage(Model):
device = fields.ForeignKeyField("models.Device", related_name="log_messages")
date_created = fields.DatetimeField(auto_now_add=True)
message = fields.CharField(max_length=1024)
@init_memory_sqlite
async def main() -> None:
await LogMessage.filter(device__name="test").delete()
if __name__ == "__main__":
run_async(main())
Expected behavior
In the example above, all "LogMessage" rows referencing devices having the name "test" should be deleted.
Instead, an invalid SQL DELETE query is generated.
Describe the bug
Using a filter query to select rows for deletion fails if the filter query is a related field query (i.e. across a foreign key).
To Reproduce
Expected behavior
In the example above, all "LogMessage" rows referencing devices having the name "test" should be deleted.
Instead, an invalid SQL DELETE query is generated.