@@ -256,25 +256,27 @@ Harness.test({
256256 dataType : 'int' ,
257257 references : {
258258 table : 'user' ,
259- column : 'id'
259+ column : 'id' ,
260+ onDelete : 'restrict' ,
261+ onUpdate : 'set null'
260262 }
261263 } ]
262264 } ) . create ( ) ,
263265 pg : {
264- text : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id"))' ,
265- string : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id"))'
266+ text : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE SET NULL )' ,
267+ string : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE SET NULL )'
266268 } ,
267269 sqlite : {
268- text : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id"))' ,
269- string : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id"))'
270+ text : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE SET NULL )' ,
271+ string : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE SET NULL )'
270272 } ,
271273 mysql : {
272- text : 'CREATE TABLE `post` (`userId` int REFERENCES `user`(`id`))' ,
273- string : 'CREATE TABLE `post` (`userId` int REFERENCES `user`(`id`))'
274+ text : 'CREATE TABLE `post` (`userId` int REFERENCES `user`(`id`) ON DELETE RESTRICT ON UPDATE SET NULL )' ,
275+ string : 'CREATE TABLE `post` (`userId` int REFERENCES `user`(`id`) ON DELETE RESTRICT ON UPDATE SET NULL )'
274276 } ,
275277 oracle : {
276- text : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id"))' ,
277- string : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id"))'
278+ text : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE SET NULL )' ,
279+ string : 'CREATE TABLE "post" ("userId" int REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE SET NULL )'
278280 } ,
279281 params : [ ]
280282} ) ;
@@ -643,4 +645,84 @@ Harness.test({
643645 string : 'CREATE TABLE "post" ("id" int PRIMARY KEY)'
644646 } ,
645647 params : [ ]
646- } ) ;
648+ } ) ;
649+
650+ Harness . test ( {
651+ query : Table . define ( {
652+ name : 'post' ,
653+ columns : [ {
654+ name : 'id' ,
655+ dataType : 'int' ,
656+ primaryKey : true
657+ } , {
658+ name : 'blog_id' ,
659+ dataType : 'int'
660+ } , {
661+ name : 'user_id' ,
662+ dataType : 'int'
663+ } ] ,
664+ foreignKeys : {
665+ table : 'users' ,
666+ columns : [ 'blog_id' , 'user_id' ] ,
667+ refColumns : [ 'id' , 'user_id' ]
668+ }
669+ } ) . create ( ) ,
670+ pg : {
671+ text : 'CREATE TABLE "post" ("id" int PRIMARY KEY, "blog_id" int, "user_id" int, FOREIGN KEY ( "blog_id", "user_id" ) REFERENCES "users" ( "id", "user_id" ))' ,
672+ string : 'CREATE TABLE "post" ("id" int PRIMARY KEY, "blog_id" int, "user_id" int, FOREIGN KEY ( "blog_id", "user_id" ) REFERENCES "users" ( "id", "user_id" ))'
673+ } ,
674+ sqlite : {
675+ text : 'CREATE TABLE "post" ("id" int PRIMARY KEY, "blog_id" int, "user_id" int, FOREIGN KEY ( "blog_id", "user_id" ) REFERENCES "users" ( "id", "user_id" ))' ,
676+ string : 'CREATE TABLE "post" ("id" int PRIMARY KEY, "blog_id" int, "user_id" int, FOREIGN KEY ( "blog_id", "user_id" ) REFERENCES "users" ( "id", "user_id" ))'
677+ } ,
678+ mysql : {
679+ text : 'CREATE TABLE `post` (`id` int PRIMARY KEY, `blog_id` int, `user_id` int, FOREIGN KEY ( `blog_id`, `user_id` ) REFERENCES `users` ( `id`, `user_id` ))' ,
680+ string : 'CREATE TABLE `post` (`id` int PRIMARY KEY, `blog_id` int, `user_id` int, FOREIGN KEY ( `blog_id`, `user_id` ) REFERENCES `users` ( `id`, `user_id` ))'
681+ } ,
682+ params : [ ]
683+ } ) ;
684+
685+ Harness . test ( {
686+ query : Table . define ( {
687+ name : 'replies' ,
688+ columns : [ {
689+ name : 'id' ,
690+ dataType : 'int' ,
691+ primaryKey : true
692+ } , {
693+ name : 'blog_id' ,
694+ dataType : 'int'
695+ } , {
696+ name : 'post_id' ,
697+ dataType : 'int'
698+ } , {
699+ name : 'user_id' ,
700+ dataType : 'int'
701+ } ] ,
702+ foreignKeys : [ {
703+ table : 'users' ,
704+ columns : [ 'blog_id' , 'user_id' ] ,
705+ onDelete : 'no action'
706+ } , {
707+ name : 'posts_idx' ,
708+ table : 'posts' ,
709+ columns : [ 'blog_id' , 'post_id' ] ,
710+ refColumns : [ 'blog_id' , 'id' ] ,
711+ onDelete : 'cascade' ,
712+ onUpdate : 'set default'
713+ } ]
714+ } ) . create ( ) ,
715+ pg : {
716+ text : 'CREATE TABLE "replies" ("id" int PRIMARY KEY, "blog_id" int, "post_id" int, "user_id" int, FOREIGN KEY ( "blog_id", "user_id" ) REFERENCES "users" ON DELETE NO ACTION, CONSTRAINT "posts_idx" FOREIGN KEY ( "blog_id", "post_id" ) REFERENCES "posts" ( "blog_id", "id" ) ON DELETE CASCADE ON UPDATE SET DEFAULT)' ,
717+ string : 'CREATE TABLE "replies" ("id" int PRIMARY KEY, "blog_id" int, "post_id" int, "user_id" int, FOREIGN KEY ( "blog_id", "user_id" ) REFERENCES "users" ON DELETE NO ACTION, CONSTRAINT "posts_idx" FOREIGN KEY ( "blog_id", "post_id" ) REFERENCES "posts" ( "blog_id", "id" ) ON DELETE CASCADE ON UPDATE SET DEFAULT)'
718+ } ,
719+ sqlite : {
720+ text : 'CREATE TABLE "replies" ("id" int PRIMARY KEY, "blog_id" int, "post_id" int, "user_id" int, FOREIGN KEY ( "blog_id", "user_id" ) REFERENCES "users" ON DELETE NO ACTION, CONSTRAINT "posts_idx" FOREIGN KEY ( "blog_id", "post_id" ) REFERENCES "posts" ( "blog_id", "id" ) ON DELETE CASCADE ON UPDATE SET DEFAULT)' ,
721+ string : 'CREATE TABLE "replies" ("id" int PRIMARY KEY, "blog_id" int, "post_id" int, "user_id" int, FOREIGN KEY ( "blog_id", "user_id" ) REFERENCES "users" ON DELETE NO ACTION, CONSTRAINT "posts_idx" FOREIGN KEY ( "blog_id", "post_id" ) REFERENCES "posts" ( "blog_id", "id" ) ON DELETE CASCADE ON UPDATE SET DEFAULT)'
722+ } ,
723+ mysql : {
724+ text : 'CREATE TABLE `replies` (`id` int PRIMARY KEY, `blog_id` int, `post_id` int, `user_id` int, FOREIGN KEY ( `blog_id`, `user_id` ) REFERENCES `users` ON DELETE NO ACTION, CONSTRAINT `posts_idx` FOREIGN KEY ( `blog_id`, `post_id` ) REFERENCES `posts` ( `blog_id`, `id` ) ON DELETE CASCADE ON UPDATE SET DEFAULT)' ,
725+ string : 'CREATE TABLE `replies` (`id` int PRIMARY KEY, `blog_id` int, `post_id` int, `user_id` int, FOREIGN KEY ( `blog_id`, `user_id` ) REFERENCES `users` ON DELETE NO ACTION, CONSTRAINT `posts_idx` FOREIGN KEY ( `blog_id`, `post_id` ) REFERENCES `posts` ( `blog_id`, `id` ) ON DELETE CASCADE ON UPDATE SET DEFAULT)'
726+ } ,
727+ params : [ ]
728+ } ) ;
0 commit comments