Re: Problem modeling parent child relationship

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Sep 20 2004 - 13:27:40 EDT

  • Next message: kalpesh modi: "inserting blob"

    Hi Adrian,

    The actual generated SQL ideally should look like "SELECT t0.ID,
    t0.PARENT_CONTENT_ID FROM CONTENT t0 WHERE t0.PARENT_CONTENT_ID = ?",
    without a joun, and that's in fact the SQL generated in a similar
    situation in our test cases. So I suspect a problem is with your
    mapping. Double-check this:

    1. DbRelationship "toParent" is a to-one, not to-many relationship.
    2. there is a reverse DbRelationship across the same joins that is to
    many.

    Andrus

    On Sep 20, 2004, at 7:55 AM, Adrian Popa wrote:
    > Hi,
    >
    > I am trying to model ,using Cayenne, a parent-child relationship for
    > entities stored in the same table. I have a table "content" with 2
    > fields: "id" and "parent_id". "id" is the primary key for the table. I
    > defined a db relationship from "parent_id" to "id" named "toParent".
    > On the content entity I defined a relationship parentContent using the
    > db relationship toParent. When I call getParentContent the generated
    > sql query displayed in the log is something like that:
    >
    > SELECT DISTINCT t0.ID, t0.PARENT_CONTENT_ID FROM CONTENT t0, CONTENT
    > t1 WHERE t0.ID = t1.PARENT_CONTENT_ID AND ((t0.ID = ?)
    >
    > but what I would expect would be:
    >
    > SELECT DISTINCT t0.ID, t0.PARENT_CONTENT_ID FROM CONTENT t0, CONTENT
    > t1 WHERE t0.ID = t1.PARENT_CONTENT_ID AND ((t1.ID = ?)
    >
    > Is this a bug or there is a problem with the way I tried to model the
    > relationship?
    >
    > Best regards,
    > Adrian Popa
    >



    This archive was generated by hypermail 2.0.0 : Mon Sep 20 2004 - 13:27:45 EDT