Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Message from discussion Ticket #8161 - Please help me fix this.
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alex Gaynor  
View profile  
 More options Mar 11 2009, 11:41 am
From: Alex Gaynor <alex.gay...@gmail.com>
Date: Wed, 11 Mar 2009 10:41:02 -0500
Local: Wed, Mar 11 2009 11:41 am
Subject: Re: Ticket #8161 - Please help me fix this.

On Wed, Mar 11, 2009 at 10:31 AM, Madhusudan C.S <madhusuda...@gmail.com>wrote:

> Hi all,
>      I wanted to fix this bug. I just went through the code to see what was
> happening. For the same sample code given in the ticket, these were my
> findings:

> The schema generated looks like this and there is no issue with it:
> CREATE TABLE "testapp_childmodel" (
>     "parentmodel_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES
> "testapp_parentmodel" ("id"),
>     "text" text NOT NULL
> );
> CREATE TABLE "testapp_parentmodel" (
>     "id" integer NOT NULL PRIMARY KEY,
>     "slug" varchar(50) NOT NULL
> );
> CREATE TABLE "testapp_parentmodel_links" (
>     "id" integer NOT NULL PRIMARY KEY,
>     "from_parentmodel_id" integer NOT NULL REFERENCES "testapp_parentmodel"
> ("id"),
>     "to_parentmodel_id" integer NOT NULL REFERENCES "testapp_parentmodel"
> ("id"),
>     UNIQUE ("from_parentmodel_id", "to_parentmodel_id")
> );

> CREATE INDEX "testapp_parentmodel_slug" ON "testapp_parentmodel" ("slug");

> I inserted test1, test2 and test3(all names being values of slug field) to
> ParentModel and linked test1 and test3 to test2 through links field. There
> seems to be no issues. Then I inserted testc1, testc2 and testc3 to
> ChildModel and linked testc2 and testc3 to testc1 through inherited links
> field. Now I can see only to links, i.e
> I get these results in the interactive interpreter:

> >>> from dummy.testapp.models import ParentModel, ChildModel
> >>> c1 = ChildModel.objects.get(slug='testc1')
> >>> c2 = ChildModel.objects.get(slug='testc2')
> >>> c3 = ChildModel.objects.get(slug='testc3')
> >>> c1.links.all()
> []
> >>> c2.links.all()
> [<ParentModel: testc1>]
> >>> c3.links.all()
> [<ParentModel: testc1>]

> This means only to links are being queried and not from links for the
> inherited model. I just saw how the queries are working and these are the
> queries constructed for c1, c2 and c3 respectively.

> SELECT "testapp_parentmodel"."id", "testapp_parentmodel"."slug" FROM
> "testapp_parentmodel" INNER JOIN "testapp_parentmodel_links" ON
> ("testapp_parentmodel"."id" =
> "testapp_parentmodel_links"."to_parentmodel_id") WHERE
> "testapp_parentmodel_links"."from_parentmodel_id" = 4  LIMIT 21

> SELECT "testapp_parentmodel"."id", "testapp_parentmodel"."slug" FROM
> "testapp_parentmodel" INNER JOIN "testapp_parentmodel_links" ON
> ("testapp_parentmodel"."id" =
> "testapp_parentmodel_links"."to_parentmodel_id") WHERE
> "testapp_parentmodel_links"."from_parentmodel_id" = 5  LIMIT 21

> SELECT "testapp_parentmodel"."id", "testapp_parentmodel"."slug" FROM
> "testapp_parentmodel" INNER JOIN "testapp_parentmodel_links" ON
> ("testapp_parentmodel"."id" =
> "testapp_parentmodel_links"."to_parentmodel_id") WHERE
> "testapp_parentmodel_links"."from_parentmodel_id" = 6  LIMIT 21

> From what I see the queries must be actually UNION of two queries which
> fetch data both from, "from" and "to" fields in the
> "testapp_parentmodel_links" table.It should look some thing like this, from
> what I have understood:

> SELECT "testapp_parentmodel"."id", "testapp_parentmodel"."slug" FROM
> "testapp_parentmodel" INNER JOIN "testapp_parentmodel_links" ON
> ("testapp_parentmodel"."id" =
> "testapp_parentmodel_links"."to_parentmodel_id") WHERE
> "testapp_parentmodel_links"."from_parentmodel_id" = 4  LIMIT 21
> UNION
> SELECT "testapp_parentmodel"."id", "testapp_parentmodel"."slug" FROM
> "testapp_parentmodel" INNER JOIN "testapp_parentmodel_links" ON
> ("testapp_parentmodel"."id" =
> "testapp_parentmodel_links"."from_parentmodel_id") WHERE
> "testapp_parentmodel_links"."to_parentmodel_id" = 4  LIMIT 21

> Is this an elegant approach? If so can some one help me implement this? I
> went through the code of QuerySet, Manager classes and other parts of
> django.db.models. How to go about from here? I am very keen on fixing this
> issue. Kindly help me.

> --
> Thanks and regards,
>  Madhusudan.C.S

> Blogs at: www.madhusudancs.info
> Official Email ID: madhusu...@madhusudancs.info

> P.S: I am really sorry if the text is not wrapped. I am still not
> understanding how wrapping works here. Will correct it from next mail. Hope
> Auto text wrapping works.

This looks like it may just be a symptom of
http://code.djangoproject.com/ticket/10237 if I'm reading htis correctly.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.