cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Haul <h...@informatik.tu-darmstadt.de>
Subject Re: Database Actions - Multiple Deletion
Date Sun, 18 Apr 2004 20:59:06 GMT
Davide wrote:
> Hi all i'm having a problem.
> 
> I've a db with 2 tables, one takes posts and one other takes comments. 
> there can be more comments related to a post, so when i delete a row 
> form posts i want to delete every related comment from comments. How to do?
> 
> this is the descriptor i use to delete a post:
> 
> <Posts>
>     <connection>mcblogger</connection>
>     <table name="Posts" alias="Posts">
>         <keys>
>             <key name="Post_ID" type="int" autoincrement="true">
>                 <mode name="auto"  type="autoincr"/>
>             </key>
>         </keys>
>     </table>
> </Posts>
> 
> and it run. How to delete also related comments from table comment?
> to delete a comment i use this descriptor:
> 
> <Comments>
>     <connection>mcblogger</connection>
>     <table name="Comments" alias="Comments">
>         <keys>
>             <key name="Comment_ID" type="int" autoincrement="true">
>                 <mode name="auto"  type="autoincr"/>
>             </key>
>         </keys>
>     </table>
> </Comments>
> 
> i tried this but it doesn't run:
> 
>     <table name="Posts" alias="Posts">
>         <keys>
>             <key name="Post_ID" type="int" autoincrement="true">
>                 <mode name="auto"  type="autoincr"/>
>             </key>
>         </keys>
>     </table>
>     
>     <table name="Comments" alias="Comments">
>         <keys>
>             <key name="Comment_ID" type="int" set="slave">
>             </key>
>         </keys>
>         <values>
>             <value name="Post_ID" type="int" set="master"/>
>         </values>
>     </table>

You're almost there.

Two issues: First, deletion considers only key columns and second 
missing is how the Post_ID is communicated to the Comments table.

Since you probably don't want to change the schema design, and you
don't want to do the SQL yourself but stay with the database actions,
the easiest way would be to have a second schema description for the
Comments table that claims that Post_ID is the key and use that for
the delete action. This way you don't event need to care how the ID
is read from the other table :-)

      <table name="Comments" alias="Comments_delete_posts">
          <keys>
              <key name="Post_ID" type="int">
              </key>
          </keys>
          <values>
          </values>
      </table>

HTH
	Chris.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message