Hi John,

I played with this from a onetomany prespective and quickly learned that I
had an object explosion on my hands since each object would maintain a
reference to it's parent and a collection of child objects.  Instead, I
modeled it with simplicity and performance in mind.  With manytoone, the
child object will have a hasParent() method and I can get the full path to
the top level parent object using recursion.  Here's an example method for
retrieving a path to the root from any self-referencing (transfer) object
with manytoone relationship (assuming the object has a getName() method).

<cffunction name="getTreePath" access="public" output="false"
returntype="string">
        <cfargument name="obj" type="any" required="true">
        <cfargument name="path" type="string" required="false" default="">
        <cfset var treePath = "/" & arguments.obj.getName() &
arguments.path>
        <cfif arguments.obj.hasParent()>
            <cfset treePath =
getTreePath(obj=arguments.obj.getParent(),path=treePath)>
        </cfif>
        <cfreturn treePath>
    </cffunction>

I use something similar for a home grown cms that has parent/child "pages".
Using mod_rewrite I create SES friendly urls based on the page names. So,
you could very easily build a breadcrumb trail in this manner, or with a
little sql, create a nested nav of categories.  Here's a link to a page on
the site I mentioned above.

http://www.slcc.ca/about-us/tale-of-two-nations/protocol-agreement

Cheers,

Paul


On Wed, Oct 15, 2008 at 10:19 AM, John Barlow <[EMAIL PROTECTED]> wrote:

>
> I see how that could work, but wouldn't that also remove all of the
> handy child functions that the onetomany relationship would give you?
>
> On Oct 15, 12:31 pm, "Paul Marcotte" <[EMAIL PROTECTED]> wrote:
> > Hi John,
> >
> > I would suggest using a manytoone for nesting categories. The object
> > definition for your category would include
> >
> > <manytoone name="Parent" lazy="true">
> >     <link to="Category" column="category_parent_id"/>
> > </manytoone>
> >
> > Note that if you use a table column for an object relationship, you
> cannot
> > have a property referencing the same column.  I'm guessing that is why
> your
> > sql has two references to category_parent_id.
> >
> > Cheers,
> >
> > Paul
> >
> >
> >
> > On Wed, Oct 15, 2008 at 7:32 AM, John Barlow <[EMAIL PROTECTED]> wrote:
> >
> > > Greetings all,
> >
> > > I've been racking my brain for about two days to try to figure this
> > > out.  I have a category table, consisting of, among other things, a
> > > category_id and a category_parent_id.  The idea is that categories can
> > > be sub categories of others (hence the category_parent_id) and have a
> > > null parent if they are the root node.
> >
> > > I set up a onetomany relationship linking the category_id to the
> > > parent_id with lazy loading and everything was working beautifully for
> > > reading.  The problem cropped up when I tried to save a record.
> >
> > > The error that came back was a SQL error, stating "category_parent_id
> > > appears more than once in the result column list."  From what I can
> > > find, this error occurs if you have two tables and have the
> > > relationship defined on both tables.  The solution there is to remove
> > > a relationship definition from one of the tables and all is well.
> >
> > > Since this is referencing itself, it is inherently getting both sides
> > > of the definition defined, which I think is what is causing this to
> > > break.  I checked the SQL, and indeed it is taking on an extra
> > > category_parent_id to the end of the insert statement.
> >
> > > I'm not sure if this is a Transfer bug or if I'm trying to use it in a
> > > way it wasn't meant to, but having a self-referencing table like this
> > > seems like a reasonable thing one would want to be able to model.  For
> > > the record, I did get around it by using a link table that has two
> > > columns that point to the category_id field in the category table and
> > > a Many to Many relationship.  Ideally, I'd like to not use an extra
> > > table to do this.
> >
> > > I just wanted to bring this to the masses because I couldn't find
> > > anything on this and felt it may have been overlooked.  What I WAS
> > > able to find was in reference to hibernate.
> >
> > > System specs:
> > > -Transfer 1.0
> > > -CF7
> > > -MSSQL 2005
> > > -XP
> >
> > --
> > Paul Marcotte
> > Fancy Bread - in the heart or in the head?http://www.fancybread.com
>
> >
>


-- 
Paul Marcotte
Fancy Bread - in the heart or in the head?
http://www.fancybread.com

--~--~---------~--~----~------------~-------~--~----~
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer

You received this message because you are subscribed to the Google Groups 
"transfer-dev" 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/transfer-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to