diff options
| author | Moayad Mardini <moayad.m@gmail.com> | 2014-06-12 20:43:30 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-06-12 16:42:44 -0400 |
| commit | 26983c4c6414f00a2bcf364436ecce0f5e73851d (patch) | |
| tree | 3a9a0a7c030c58edd0450d44887169fd3563ece9 | |
| parent | 15fe4ab671bd24ebd73e3b997b63d8e122c03073 (diff) | |
[1.6.x] Fixed #22349 -- Added a note clarifying `RawQuerySet` has no `__len__`.
Thanks cdestigter for the report.
Backport of 2d425116e2 from master
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | docs/topics/db/sql.txt | 14 |
2 files changed, 14 insertions, 1 deletions
@@ -396,6 +396,7 @@ answer newbie questions, and generally made Django that much better: Javier Mansilla <javimansilla@gmail.com> masonsimon+django@gmail.com Manuzhai + Moayad Mardini <moayad.m@gmail.com> Petr Marhoun <petr.marhoun@gmail.com> Petar Marić <http://www.petarmaric.com/> Nuno Mariz <nmariz@gmail.com> diff --git a/docs/topics/db/sql.txt b/docs/topics/db/sql.txt index e577ca3648..478e2898f1 100644 --- a/docs/topics/db/sql.txt +++ b/docs/topics/db/sql.txt @@ -33,7 +33,8 @@ return model instances: This method takes a raw SQL query, executes it, and returns a ``django.db.models.query.RawQuerySet`` instance. This ``RawQuerySet`` instance -can be iterated over just like a normal QuerySet to provide object instances. +can be iterated over just like a normal +:class:`~django.db.models.query.QuerySet` to provide object instances. This is best illustrated with an example. Suppose you have the following model:: @@ -84,6 +85,17 @@ options that make it very powerful. both rows will match. To prevent this, perform the correct typecasting before using the value in a query. +.. warning:: + + While a ``RawQuerySet`` instance can be iterated over like a normal + :class:`~django.db.models.query.QuerySet`, ``RawQuerySet`` doesn't + implement all methods you can use with ``QuerySet``. For example, + ``__bool__()`` and ``__len__()`` are not defined in ``RawQuerySet``, and + thus all ``RawQuerySet`` instances are considered ``True``. The reason + these methods are not implemented in ``RawQuerySet`` is that implementing + them without internal caching would be a performance drawback and adding + such caching would be backward incompatible. + Mapping query fields to model fields ------------------------------------ |
