Opened 11 years ago
Closed 11 years ago
#20826 closed Cleanup/optimization (fixed)
Move `Manager.raw()` and `Manager._insert()` to the QuerySet class.
Reported by: | loic84 | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
After the introduction of #20625, most methods that involve a DB query have been removed from Manager
and are automatically proxied to QuerySet
, only raw()
and _insert()
remain. After discussion with @akaariai on IRC we came to the conclusion that it would make sense to move these to the QuerySet
class as well.
The previous goal was for QuerySet
to focus on retrieval, but this has somewhat failed as most methods that could belong to Manager
(like create()
) already live on the QuerySet
class. The introduction of hybrid methods like get_or_create()
or update_or_create()
also demonstrates that the distinction between the different kinds of queries is not obvious to make.
If this ticket is accepted, the new objective would be defined as follows:
- Anything "query" belongs to
QuerySet
. Manager
is responsible for the integration between aModel
and aQuerySet
.Manager
works as a hook to pre/post-process or even replaceQuerySet
methods when needed. (See current implementation ofManager.all()
orRelatedManager.create()
).
Change History (4)
comment:1 by , 11 years ago
Has patch: | set |
---|
comment:2 by , 11 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
Assuming the idea isn't rejected by someone else, the patch looks good.
comment:3 by , 11 years ago
I think the move makes sense. .raw() belongs to queryset just as much as .create(). So, things will be a bit more consistent after the move.
comment:4 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
PR https://github.com/django/django/pull/1411