Open sinaso opened 4 years ago
Thanks for the example. I have a better idea of the use case now.
What operands are supported for a subquery?
I would assume __in
and __not_in
? Anything else?
Another useful option would be __exists_in
, as a useful optimization to generate slightly better SQL?
Also note that for the
through
field my code allows the model reference to be used, (tortoise only allows actual database table name). I have skipped the definition ofProductImage
model here.
Probably more accurate to say that Tortoise doesn't support custom through tables at this stage for a ManyToManyField at all.
Its pretty general, as it uses PyPika, I haven't played with it a lot, but I assume it could be anything.
Custom through tables were working fine actually, it's just that the default forward and backward table columns where being set to something really weird, (I cannot recall what it was exactly), once I provided forward and backward field names it was working fine.
In my code, I also fixed the default forward and backward field names to very obvious ones.
In my code, I also fixed the default forward and backward field names to very obvious ones.
Thanks for the heads up. We don't want to break existing users db's. That's way worse than breaking API.
These are a few examples related to conversations #336 and #236 Assume the following models:
Note
Product
is inManyToMany
relationship withImage
andForeignKey
(or OneToMany) relationship withBrand
.Also note that for the
through
field my code allows the model reference to be used, (tortoise only allows actual database table name). I have skipped the definition ofProductImage
model here.Now the following code prefetches only the first four images of a product. Notice the
OuterRef
andPrefetch
on aManyToMany
field.The following method, is almost the same thing. It prefetches the first six products for any brand. Notice the
OuterReft
andPrefetch
on aForeignKey
field.hope this helps.