From 43b35a0a633249a068281c849aae54e8ed3f5c3a Mon Sep 17 00:00:00 2001
From: Sebastian Noack <sebastian.noack@gmail.com>
Date: Thu, 29 May 2008 14:15:57 +0200
Subject: [PATCH] Added test and documentation for sub-selects.
---
docs/db-api.txt | 12 ++++++++++++
tests/regressiontests/queries/models.py | 4 ++++
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/docs/db-api.txt b/docs/db-api.txt
index 405ed87..07095fa 100644
a
|
b
|
SQL equivalent::
|
1368 | 1368 | |
1369 | 1369 | SELECT ... WHERE id IN (1, 3, 4); |
1370 | 1370 | |
| 1371 | .. note:: |
| 1372 | It is possible to realize sub-selects by using ``in`` lookup. |
| 1373 | |
| 1374 | Example:: |
| 1375 | |
| 1376 | Entry.objects.filter( |
| 1377 | blog__in=Blog.objects.filter(name='Cheddar Talk').values('pk').query) |
| 1378 | |
| 1379 | SQL equivalent:: |
| 1380 | |
| 1381 | SELECT ... WHERE id IN (SELECT id FROM ... WHERE name = 'Cheddar Talk'); |
| 1382 | |
1371 | 1383 | startswith |
1372 | 1384 | ~~~~~~~~~~ |
1373 | 1385 | |
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 5beaf5f..caee08f 100644
a
|
b
|
in MySQL. This exercises that case.
|
701 | 701 | >>> mm = ManagedModel.objects.create(data='mm1', tag=t1, is_public=True) |
702 | 702 | >>> ManagedModel.objects.update(data='mm') |
703 | 703 | |
| 704 | Sub-select using in lookup with Query object. |
| 705 | >>> Author.objects.filter(extra__in=ExtraInfo.objects.filter(note__misc='foo').values('pk').query) |
| 706 | [<Author: a1>, <Author: a2>] |
| 707 | |
704 | 708 | """} |
705 | 709 | |