On Thu, Jan 19, 2012 at 5:14 PM, Adrian Holovaty <[email protected]> wrote:
> 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):
>
...
> 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?
This one seems much more likely to be a breaking change - it isn't
that unusual to do something like:
special_book = Book.objects.get(...)
special_book.fiddly_bit = True
# note no save
for author in Author.objects.all():
for book in author.books.all():
if book.fiddly_bit:
book.related_books.add(special_book)
The semantics of this change under a new caching layer.
If the intention is that it's really the same object (and not a new
instance of the same db object retrieved from a caching layer) then
this introduces actions at a distance.
This is ye olde Django ticket:
https://code.djangoproject.com/ticket/17
And for context: ;-)
http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Computer+Science.aspx
--
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.