Foreign key references key in same table?

5 views
Skip to first unread message

lumsden

unread,
Jan 29, 2007, 12:31:25 PM1/29/07
to Php Object Generator
Can a foreign key reference a key in the same table with POG?

destination_id (PK)
destination_parent_id (FK ??? as it must take a value from
destination_id)
destination_name
destination_description

Cheers

Lumsden

Joel

unread,
Jan 29, 2007, 4:36:17 PM1/29/07
to Php Object Generator
Not inherently.

i.e a child class in POG cannot have a parent equal to itself and vice-
versa, although, I know Mark and I were talking about a simple and
elegant workaround he came up with while working on a project... He
may elaborate if he finds a minute or two.

But the short answer, from the generator's point of view, is no.

lumsden

unread,
Jan 29, 2007, 6:42:35 PM1/29/07
to Php Object Generator
I will look forward to when Mark can spend a minute or two.

Cheers

Lumsden

Joel

unread,
Jan 30, 2007, 12:16:43 AM1/30/07
to Php Object Generator
>From Mark's email:

<--snip-->

Hi Joel
yes - it is kind of simple...

objectA
-objectaId
-name
-MyParentObjectAId

when you need all the children:
$children = $objectA->GetList("MyParentObjectAId","=",$this-
>objectaId);

when you need the parent:
$parent = $objectA->-MyParentObjectAId;

that's it.

-Mark

<--snip-->

lumsden

unread,
Jan 30, 2007, 5:00:54 AM1/30/07
to Php Object Generator
Does he mean:
$parent = $objectA->MyParentObjectAId;

instead of:
$parent = $objectA->-MyParentObjectAId;

Unless you reply, I will assume that minus sign before
MyParentObjectAId is just a typo.

Cheers

Lumsden

lumsden

unread,
Jan 30, 2007, 5:02:05 AM1/30/07
to Php Object Generator
Forgot to say thanks very much again.

Cheers

Lumsden

Crispy

unread,
Jan 31, 2007, 8:51:13 PM1/31/07
to Php Object Generator
oh - my bad,
typo - plus logical error. It's always so obvious when you read it
again... ;-)

$parent = $objectA->Get($objectA->MyParentObjectAId);

I missed the getting of the actual object... Sorry about that -
-Mark

Reply all
Reply to author
Forward
0 new messages