#11402: exists() method on QuerySets
---------------------------------------------------+------------------------
Reporter: Alex | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: 1.0
Resolution: | Keywords:
Stage: Accepted | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Comment (by lukeplant):
Hi Alex,
Good work! My comments:
* Could you be persuaded to use 'any()' instead of 'exists()'? It's a
bit of a bikeshed issue, and you're the one painting it, but I do think
that
{{{
if Foo.objects.filter(blah).any():
}}}
has a slightly more obvious meaning and reads better than
{{{
if Foo.objects.filter(blah).exists():
}}}
especially as you are running into the singular/plural issue ("exists"
sounds appropriate for querying the existence of a single item, but is
confusing if there might be many). Also, `any` is evocative of
[http://docs.python.org/library/functions.html#any any], complete with the
implied efficient behaviour.
* Obviously this needs tests (for both outcomes). Either in
modeltests/lookup/models.py or modeltests/basic/models.py, probably the
former.
* In the docs, I would say "This will perform the check in the most
efficient way possible", rather than "This will perform the query in the
simplest way possible". The latter implies first that the same query will
be performed, or that a simplified query will be performed, both of which
are slightly misleading.
* `Query.has_results()` needs a docstring, and it should mention that it
destructively updates the query object. In fact, putting the `clone()`
call into `has_results()` would be better AFAICS - this would make it work
like `get_count()`, reducing unwanted surprises should it be used from
somewhere else.
--
Ticket URL: <http://code.djangoproject.com/ticket/11402#comment:6>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---