Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Joins being dropped when specifying multiple fields in `select_related` #46
Comments
|
Hi, This project seems stale and from what I saw on encode page it's not a priority right now. Since I was tired with reinventing the wheel and needed something as soon as possible I created ormar package, that was inspired by this one. Ormar bases its validation on pydantic so it can be used directly with fastapi as response and request models. This issue was implemented in ormar, so feel free to check it out: https://github.com/collerek/ormar |
Hello again. I have an issue with using multiple tables in
select_relatedthat results in the incorrect SQL being generated.Using these tables as an example (irrelevant fields omitted):
And using this query to illustrate:
With this query, some JOIN expressions are dropped from the resulting SQL, so it looks something like this:
What I'd expect to see is the
tracktable also getting aJOINexpression, rather than just appearing in theFROM. This results in the incorrect behaviour of, as far as I can make out, joining every combination of track and post together. (I didn't even realise this was valid SQL, so I've learned something.)I believe the issue is redefining
select_fromhere, inmodels.py:I think the core problem is the redefinition of
select_fromon line 76, as this stops the joins from being built up each time through the loop. So if that line is removed, it seems to solve the issue.