-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 01/19/2012 11:02 AM, Jeremy Dunck wrote:
> On Thu, Jan 19, 2012 at 5:14 PM, Adrian Holovaty <[email protected]> wrote:
>> 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
I don't think Adrian is proposing anything as extensive as #17. What
he's proposing (IIUC) wouldn't change the semantics of your sample code
at all. All it would do is prepopulate the FK field on the results of a
reverse-FK query, so the innermost "book.author" here doesn't need to do
a query:
for author in Author.objects.all():
for book in author.books.all():
book.author
There wouldn't be any action-at-a-distance with other Book instances.
Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk8YXbgACgkQ8W4rlRKtE2fWPQCfXUp1NVmTaNvwZVPpyOsFVAtP
+UsAoJqJ5l0nz+98L+Z+dJ8rdPe5DeM8
=BTg6
-----END PGP SIGNATURE-----
--
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.