Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#7862 closed (duplicate)

query result set should use same query object passed into query method.

Reported by: towjzhou@… Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This code:

user = get_object_or_404(User, pk=100)
profile = UserProfile.objects.get(user=user)
# Here id(user) != id(profile.user), there are 2 different objects. 
# And user.save() will override profile.user.save(), in some complex code may be cause bugs.

If use Model instance to do query, results should use these model instance.

Change History (3)

comment:1 by Alex Gaynor, 16 years ago

Resolution: duplicate
Status: newclosed

This is a duplicate of #17 as far as I can tell, if this is not correct, feel free to repoen.

comment:2 by James Bennett, 16 years ago

This is indeed a duplicate of #17, which grew far beyond its original scope into a proposal for identity mapping in the ORM.

comment:3 by towjzhou@…, 16 years ago

But I always not need the full power of identity mapping like java hibernate does.

The most situation that need identity mapping is:

obj = query_for_obj(xxx=model_instance...)
# now do some thing on obj or pass obj to other_functions
def other_functions(obj):
    obj2 = query_for_obj2(obj=obj)
    # here id(obj2.obj) should equal to id(obj), so obj2.obj.save() can work.
Note: See TracTickets for help on using tickets.
Back to Top