Monday, June 4, 2012

Re: how to suppress ForeignKey related query

Related objects are lazy by default, unless you're using select_related() or prefetch_related(): https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.select_related

So if you're seeing a player query and you're not using one of those methods, then I would double check your code (and templates) to make sure you're not using the player relation somewhere.

_Nik

On 6/4/2012 10:42 AM, Zheng Li wrote:
I have a class
class PlayerSoul(ModelAbstract, ModelBatchSaveHelper):
    player = models.ForeignKey(Player)
    ......

When I call
PlayerSoul.objects.all()
PlayerSoul.objects.get()
there is always an additional query for Player.

Can I delay the query for Player until I really use it.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment