Foreign keys in search_fields give wrong results some hits duplicated, some missing)
In the docs at http://www.djangoproject.com/documentation/0.96/model-api/
about search_fields, it says you can use 'the lookup API “follow” notation' to get a foreign key into your search_fields.
search_fields = (...
'filmcliplog__description' # This is the
line that causes problems
clip = models.ForeignKey(FilmClip,
description = ...
There are two problems with the resulting behavior:
1) Any matching FilmClip that has at least one FilmClipLog will show
up in the results twice.
2) Any matching FilmClip that has no FilmClipLogs will not show up at
From the mysql query log, I've found that the query looks like:
SELECT ... FROM `filmy_filmclip` INNER JOIN `filmy_filmcliplog` ...
I think the correct query would be:
SELECT DISTINCT ... FROM `filmy_filmclip` LEFT OUTER JOIN
Originally discussed at http://groups.google.com/group/django-users/browse_thread/thread/da44ae1542436d18
Change History (3)
|Patch needs improvement:
Fixed on a branch