Thursday, June 30, 2011

Re: Weird join conditions

On Thu, Jun 30, 2011 at 02:13:05PM -0700, peroksid wrote:
> Thank you, Michal,
>
> Unfortunately, I need join condition, not a WHERE clause, which can be
> easily extended with extra() method arguments.
> It is not my bad mood, simply the same condition in WHERE and ON
> produces different effect.

Hmm, could you please provide an example? (-: Don't know whether it's
the late night combined with lack of caffeine or something else but I
can't figure out the difference at the moment...

> I think rather about some method which gets together whole SQL query.
> Currently I call join() on queryset's query to join my table with part
> of target join condition.
> I could take the query assembled by "assembler" method and replace the
> part of condition with an entire one.
>
> It seems you know pretty much about Django ORM if you work on
> composite keys (great respect).
> Could you please hint me about this "assembler" method I babble about?

Well, basically, the models.sql.query.Query.join method and friends
manage a list of joins which is then processed in
models.sql.compiler.SQLCompiler.get_from_clause.

Anyway, in some cases it might be more reasonable to just write your
own query instead of fighting with the ORM to make it do what you
wanti at all cost. (-; Bear in mind that if you try to override these
deeply hidden mechanisms in your code, you'll have to keep in sync
with any internal changes and refactors. And I can assure you these
will happen in the foreseeable future. (-;

Michal

No comments:

Post a Comment