在 django ORM 中,您可以直接按關系屬性進行過濾。例如,給定表格class Product(models.Model): product_id = models.IntegerField(primary_key=True) color = models.TextField()class Sale(models.Model): sale_id = models.IntegerField(primary_key=True) timestamp = models.DateTimeField() product = models.ForeignKey(Product, on_delete=models.CASCADE)你可以做Sale.objects.filter(product__color__in=['red', 'blue'])甚至反過來Product.objects.filter(sale__timestamp__gt=datetime.now())在沒有顯式 JOIN的情況下,在 sqlalchemy 中執行此操作的正確方法是什么?
添加回答
舉報
0/150
提交
取消