You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by "Weber, Nadja" <Na...@t-systems.com> on 2003/04/24 11:11:27 UTC

Foreign key relationships

Hi all,

i have a question regarding usage of foreign key relationships in torque.
I have a table of elements. Each of those elements has one foreign key reference to another element (parent element) of the same table, thereby establishing a parent-child-hierarchy. Now, while it's easy to retrieve the parent, what would i do to retrieve all children of an element? At the moment i think of writing a select with the criteria set to the parents id, but is there any other, built-in, functionality in torque that would let me get those relationships?

Kind Regards

Nadja Weber

T-Systems 
Systems Integration 
Business Unit Entwicklungszentrum Darmstadt 
T-Systems Nova GmbH 

Re: Foreign key relationships

Posted by Eric Emminger <er...@ericemminger.com>.
Nadja

Weber, Nadja wrote:
> Hi all,
> 
> i have a question regarding usage of foreign key relationships in torque.
> I have a table of elements. Each of those elements has one foreign key reference to another element (parent element) of the same table, thereby establishing a parent-child-hierarchy. Now, while it's easy to retrieve the parent, what would i do to retrieve all children of an element? At the moment i think of writing a select with the criteria set to the parents id, but is there any other, built-in, functionality in torque that would let me get those relationships?

I don't think Torque generates any methods for getting children. At 
least, Torque hasn't done this for me, so that's my guess. I'm sure you 
could add this, however.

The easiest solution is probably to add such a method to your Element class.

Eric