We din't currently do join trimming from the beginning of the query's
tables, only from the end of the tables.
Fixing this issue only doesn't seem worth it, as the current join trimmig
code can't be adapted to handle trimming from the beginning of the query's
tables. But we might be able to trim
In the meanwhile you can directly query the intermediate model instead:
Author.books.through.objects.filter(author_id=author.id).values_list('book_id')
Le jeudi 19 novembre 2015 16:05:11 UTC-5, Cristiano Coelho a écrit :
>
> You are right. I believe an optimization like this would probably help
You are right. I believe an optimization like this would probably help just
a few people, as only fetching data from the intermediary table is a rare
thing. But if it is an easy change, which improves performance, why not?
However I think the change is quite complicated.
El jueves, 19 de
I think you didn't understand the query. You would filter by the
intermediate table directly, and filter by Usuario (as you want all
Especialidad from one Usuario), yielding 2 results as it should with a
single select from one table. Right now django translates it into a more
complicated
Hi Cristiano,
If I get it correctly you'd like m2m querying to start with the
intermediary (FROM) table and JOIN the referenced one only if more fields
than the primary key are selected.
class Book(models.Model):
name = models.CharField(max_length=100)
class Author(models.Model):
I guess that Cristiano may be right.
Making the query only on the Intermediate table would be enough for this
case, because the two columns that we need for the query are on this table,
and looks like Django is using a JOIN only to get the "id" of Especialidad.
*Here's an example:*
*GIven the
It might be a bit early in the day for me, but isn't that query already
optimised? That is, it's already eliminated a join. It hasn't joined to the
"Especialidad" table, it's only joined to the intermediate table. I *think*
the join to the intermediate table is necessary because there could be
Hello there,
Lets say I have these two models (sorry about the spanish names!) ( Django
1.8.6 and MySQL backend )
class Especialidad(models.Model):
nombre = models.CharField(max_length=250, blank=False, unique=True)
class Usuario(AbstractBaseUser):
permisosEspecialidad =