hi,

i have this kind of model:

class Storycomment(models.Model):
    ...
    story = models.ForeignKey(Story, related_name='comment_set')
    ...
    comment = models.TextField()
    parent = models.ForeignKey('self', blank=True, null=True,
related_name='child_set')
    ...

with "parent", a self referencing FK

i make a query on a story to get related comments:
comment_set = mystory.comment_set.all()

when i debug the db queries
i have a first query to get the comment stuff, which is expected

###########
SELECT
"stories_storycomment"."id","stories_storycomment"."user_id","stories_storycomment"."story_id","stories_storycomment"."show","stories_storycomment"."trashed","stories_storycomment"."comment","stories_storycomment"."parent_id","stories_storycomment"."from_ip","stories_storycomment"."created","stories_storycomment"."updated"
FROM "stories_storycomment" WHERE ("stories_storycomment"."story_id" =
32) ORDER BY "stories_storycomment"."created" ASC
#########

but for each "parent" fk that is not null i have a db request that
goes get the self referenced comment:

############""
SELECT
"stories_storycomment"."id","stories_storycomment"."user_id","stories_storycomment"."story_id","stories_storycomment"."show","stories_storycomment"."trashed","stories_storycomment"."comment","stories_storycomment"."parent_id","stories_storycomment"."from_ip","stories_storycomment"."created","stories_storycomment"."updated"
FROM "stories_storycomment" WHERE ("stories_storycomment"."id" = 2)

SELECT
"stories_storycomment"."id","stories_storycomment"."user_id","stories_storycomment"."story_id","stories_storycomment"."show","stories_storycomment"."trashed","stories_storycomment"."comment","stories_storycomment"."parent_id","stories_storycomment"."from_ip","stories_storycomment"."created","stories_storycomment"."updated"
FROM "stories_storycomment" WHERE ("stories_storycomment"."id" = 1)

SELECT
"stories_storycomment"."id","stories_storycomment"."user_id","stories_storycomment"."story_id","stories_storycomment"."show","stories_storycomment"."trashed","stories_storycomment"."comment","stories_storycomment"."parent_id","stories_storycomment"."from_ip","stories_storycomment"."created","stories_storycomment"."updated"
FROM "stories_storycomment" WHERE ("stories_storycomment"."id" = 6)

SELECT
"stories_storycomment"."id","stories_storycomment"."user_id","stories_storycomment"."story_id","stories_storycomment"."show","stories_storycomment"."trashed","stories_storycomment"."comment","stories_storycomment"."parent_id","stories_storycomment"."from_ip","stories_storycomment"."created","stories_storycomment"."updated"
FROM "stories_storycomment" WHERE ("stories_storycomment"."id" = 1)

SELECT
"stories_storycomment"."id","stories_storycomment"."user_id","stories_storycomment"."story_id","stories_storycomment"."show","stories_storycomment"."trashed","stories_storycomment"."comment","stories_storycomment"."parent_id","stories_storycomment"."from_ip","stories_storycomment"."created","stories_storycomment"."updated"
FROM "stories_storycomment" WHERE ("stories_storycomment"."id" = 1)

################

idem when i use hand made sql

it means that when i instantiate a obj with a non null self FK, a quey
is thrown on that fk

is it something that is wanted, how can i avoid that, because on a
page with 100 comments
it make a lot of unnecessary db work...

thanks
alain


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to