Subject | Design problem - multi gen |
---|---|
Author | johnsparrowuk |
Post date | 2004-06-06T16:37:13Z |
Can anyone help me with this design problem?
I've got a tree of nodes. Leaf nodes can have 0 or 1 workrecords.
Other nodes cannot have a work record pointing to them. My tables
look like this:
create table treenodes
(
idcode integer primary key,
parentnode integer,
...
foreign key (parentnode) references treenodes(idcode)
);
create table workrecords
(
idcode integer primary key,
...
foreign key (idcode) references treenodes(idcode)
);
The unique index on workrecords.idcode ensures only one workrecord
can be attached to a node. But now can I ensure workrecord's are not
assigned to non-leaf nodes???? Something like:
[trigger before insert or update on workrecords]:
select count(*) from treenodes where parentnode = new.idcode into :i;
if (i > 0) then
exception must_be_leaf;
...can only see committed records. What if something is pending???
This project is at v early stages, so table redesign is no problem
if something radical is needed.
I really want to be able to dirty-read (grin).
Hope someone can help me out!
All I can think of is having another table of 'leafnodeid's.
Touching the record when a workrecord is created for it, and
deleting it when a child node is assigned.
Thanks,
John
I've got a tree of nodes. Leaf nodes can have 0 or 1 workrecords.
Other nodes cannot have a work record pointing to them. My tables
look like this:
create table treenodes
(
idcode integer primary key,
parentnode integer,
...
foreign key (parentnode) references treenodes(idcode)
);
create table workrecords
(
idcode integer primary key,
...
foreign key (idcode) references treenodes(idcode)
);
The unique index on workrecords.idcode ensures only one workrecord
can be attached to a node. But now can I ensure workrecord's are not
assigned to non-leaf nodes???? Something like:
[trigger before insert or update on workrecords]:
select count(*) from treenodes where parentnode = new.idcode into :i;
if (i > 0) then
exception must_be_leaf;
...can only see committed records. What if something is pending???
This project is at v early stages, so table redesign is no problem
if something radical is needed.
I really want to be able to dirty-read (grin).
Hope someone can help me out!
All I can think of is having another table of 'leafnodeid's.
Touching the record when a workrecord is created for it, and
deleting it when a child node is assigned.
Thanks,
John