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:39 -0400 |
| commit | d3bf537324c1164dee45070f90d48661b27a781f (patch) | |
| tree | a1650b938633714ff4787d22b06267f832b6c175 /docs | |
| parent | d9eef1f4f7b4401a0ff6e3feb3352b6e661f705a (diff) | |
[1.7.x] Fixed #22349 -- Added a note clarifying `RawQuerySet` has no `__len__`.
Thanks cdestigter for the report.
Backport of 2d425116e2 from master
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/db/sql.txt | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/docs/topics/db/sql.txt b/docs/topics/db/sql.txt index fc10b0e4a9..f791188375 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 ------------------------------------ |
