On Wed, Jan 18, 2012 at 1:07 PM, Shai Berger <[email protected]> wrote:
> I have a small improvement to suggest for one-to-one fields: Make them cache
> back-references on related objects. That is, assume

Yes! Good improvement. And we should do the same thing for one-to-many
fields (ForeignKeys):

"""
class Author(models.Model):
    name = models.CharField(...)

class Book(models.Model):
    author = models.ForeignKey(Author)

john = Author.objects.get(name='john')
books = list(john.book_set.all())

# Does a database query, but should be smart enough to simply return john.
books[0].author
"""

I'm pretty sure there's a long-standing ticket for this, but I'm not
sure which one it is. Shai, does your solution approach this in a way
that can solve the issue for ForeignKeys as well?

Adrian

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" 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-developers?hl=en.

Reply via email to