db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Malte Stien <ma...@stien.de>
Subject Saving a tree
Date Thu, 15 May 2003 05:09:06 GMT
Hi,

I have got a table that represents a tree, i.e. it has a "parent"-relationship 
with itself. Some of the rows have a foreign-key pointing to another row in 
the same table which represents the "parent" of a particular row. However, 
some of the rows do not have a parent and thus are "roots".

I represented that in the schema by setting the "required"-field of the 
foreign key to false.

  <table name="ExpirableDataItem" description="">
    <column
      name="ExpirableDataItemID"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="ID of the ExpirableDataItem"/>
    <column
      name="PreviousExpiryDataItemID"
      required="false" <==============================================
      primaryKey="false"
      type="INTEGER"
      description=""/>
    <foreign-key foreignTable="ExpirableDataItem">
      <reference
        local="PreviousExpiryDataItemID"
        foreign="ExpirableDataItemID"/>
    </foreign-key>
  </table>

The database schema seems to be alright. I can successfully perform manual 
inserts in the Postgresql database (using psql) that look like:
- insert into expirabledataitem (expirabledataitemid) values (5004);
- insert into expirabledataitem (expirabledataitemid, 
previousexpirydataitemid) values (5005, 5004);

But the problem is that I cannot create such an object in Torque without 
setting the previousexpirydataitemid and then save it. I get the error 
message:
- expirabledataitem_fk_1 referential integrity violation - key referenced from 
expirabledataitem not found in expirabledataitem

I have the suspicous that Torque tries to save always ALL values of an object 
(whether they have been set or not) and that save tries to set the value for 
previousexpirydataitemid to 0 and since there is no such object the save 
fails. I tried to emulate that manually and got the same error message which 
supports my theory.
- insert into expirabledataitem (expirabledataitemid, 
previousexpirydataitemid) values (5007, 0);
ERROR:  expirabledataitem_fk_1 referential integrity violation - key 
referenced from expirabledataitem not found in expirabledataitem

Any ideas how to save root elements of a tree? I don't really want to use a 
dummy root element that is always there.

Thanks for any suggestions.
Malte.


Mime
View raw message