Rapid Application Development with Open Source Software

Next: Building a View Element for the Comments UP: TOC

The data model looks as follows

The SQL Data Definition Statements (DDL) look as follows:

create sequence bo_comment_id_seq;

create table bo_comment (
   id integer primary Key default nextval('bo_comment_id_seq'::regclass),
   chapter_id integer not null,
   comment_id integer,
   created  timestamp with time zone DEFAULT ('now'::text)::timestamp with time zone,  
   email character varying(255) not null,
   comment_text character varying(2000) not null
) with (oids = false);

Every value of chapter_id must reference to the table bo_chapter. Once a chapter is being deleted on comments are deleted as well. There we define a foreign key with a delete clause.

ALTER TABLE ONLY bo_comment
    ADD CONSTRAINT comment_chapter_fk FOREIGN KEY (chapter_id) REFERENCES bo_chapter(id) on delete cascade;  
Next: Building a View Element for the Comments UP: TOC