[cf-orm-dev] one-to-many relationship with the same object

3 views
Skip to first unread message

robert

unread,
Apr 30, 2010, 2:12:38 AM4/30/10
to cf-orm-dev
Hi all,

So I am building a message thread. The messages have a parentMessage
property that would be a many-to-one to a message. I also have the
childMessage property that would return a collection of child
messages.

I have come up with this:

<cfproperty name="ChildMessages" fieldtype="one-to-many"
fkcolumn="Parent_ID" column="message_ID" cfc="message">
<cfproperty name="ParentMessage" fieldtype="many-to-one"
fkcolumn="message_ID" column="Parent_ID" cfc="message" insert="false"
update="false">

I get the correct FK_ID in the Parent_ID column in the database but
when I call getParentMessage() I only get the current message's
message_ID. If I can't get the parentMessage object how would I get
just the parent_ID from the DB for a message object? Is it even
possible to map a component to do this?

Cheers,
Robert Shires

--
You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
To post to this group, send email to cf-or...@googlegroups.com.
To unsubscribe from this group, send email to cf-orm-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cf-orm-dev?hl=en.

Rupesh Kumar

unread,
Apr 30, 2010, 11:15:19 AM4/30/10
to cf-or...@googlegroups.com

Your property should look like this..

 

<cfproperty name="ChildMessages" fieldtype="one-to-many" fkcolumn="Parent_ID" column="message_ID" cfc="message" inverse="true">

 

<cfproperty name="ParentMessage"  fieldtype="many-to-one" fkcolumn="message_ID" fkcolumn="Parent_ID" cfc="message" insert="false" update="false">

 

 

Note that you define fkcolumn on both the side and it’s the same column name since the foreign key involved in the relationship is the same. Please refer to the ORM doc for more details.

 

 

robert shires

unread,
Apr 30, 2010, 11:50:15 AM4/30/10
to cf-or...@googlegroups.com
Thank you Rupesh.

I was unclear about the inverse property. In the abstract, the documentation was confusing. Now that I have a prime example it makes more sense. I am loving the new ORM features.

Robert
303-359-8383
Reply all
Reply to author
Forward
0 new messages