Hi Tone,
Either I misunderstand the docs, or I misunderstand how this can be
useful to me. Or this is not particularly useful to me.
B.objects.extra(select={'foo': 'SELECT COUNT(*) FROM app_a WHERE
b_id=app_b.id'}, where=['`foo` > 0'])
generates a SQL query:
SELECT `app_b`.`id`,(SELECT COUNT(*) FROM app_a WHERE b_id=app_b.id) AS
`foo` FROM `app_b` WHERE `foo` > 0
... which MySQL says is invalid (OperationalError: (1054, "Unknown
column 'foo' in 'where clause'")).
Similarly,
B.objects.extra(select={'foo': 'SELECT COUNT(*) as c FROM app_a WHERE
b_id=app_b.id and c > 0'})
Generates:
SELECT `app_b`.`id`,(SELECT COUNT(*) as c FROM app_a WHERE b_id=app_b.id
and c > 0) AS `foo` FROM `app_b`
Which gives:
OperationalError: (1054, "Unknown column 'c' in 'where clause'")
So... I don't think I can do this with subselects (at least with
MySQL?), I need to be able to use an OUTER JOIN.
Russell
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---