Skip to content

Commit 1e2a762

Browse files
committed
better fix for #513
1 parent 4eafbff commit 1e2a762

13 files changed

+99
-34
lines changed

tests/fixtures/blog_mysql.sql

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ CREATE TABLE `categories` (
1515

1616
INSERT INTO `categories` (`name`, `icon`) VALUES
1717
('announcement', NULL),
18-
('article', NULL);
18+
('article', NULL),
19+
('comment', NULL);
1920

2021
DROP TABLE IF EXISTS `comments`;
2122
CREATE TABLE `comments` (
2223
`id` bigint(20) NOT NULL AUTO_INCREMENT,
2324
`post_id` int(11) NOT NULL,
2425
`message` varchar(255) NOT NULL,
26+
`category_id` int(11) NOT NULL,
2527
PRIMARY KEY (`id`),
2628
KEY `post_id` (`post_id`),
27-
CONSTRAINT `comments_post_id_fkey` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`)
29+
CONSTRAINT `comments_post_id_fkey` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),
30+
CONSTRAINT `comments_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)
2831
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
2932

30-
INSERT INTO `comments` (`post_id`, `message`) VALUES
31-
(1, 'great'),
32-
(1, 'fantastic'),
33-
(2, 'thank you'),
34-
(2, 'awesome');
33+
INSERT INTO `comments` (`post_id`, `message`, `category_id`) VALUES
34+
(1, 'great', 3),
35+
(1, 'fantastic', 3),
36+
(2, 'thank you', 3),
37+
(2, 'awesome', 3);
3538

3639
DROP TABLE IF EXISTS `posts`;
3740
CREATE TABLE `posts` (

tests/fixtures/blog_pgsql.sql

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ CREATE TABLE categories (
5252
CREATE TABLE comments (
5353
id bigserial NOT NULL,
5454
post_id integer NOT NULL,
55-
message character varying(255) NOT NULL
55+
message character varying(255) NOT NULL,
56+
category_id integer NOT NULL
5657
);
5758

5859

@@ -185,17 +186,18 @@ CREATE TABLE "nopk" (
185186

186187
INSERT INTO "categories" ("name", "icon") VALUES
187188
('announcement', NULL),
188-
('article', NULL);
189+
('article', NULL),
190+
('comment', NULL);
189191

190192
--
191193
-- Data for Name: comments; Type: TABLE DATA; Schema: public; Owner: postgres
192194
--
193195

194-
INSERT INTO "comments" ("post_id", "message") VALUES
195-
(1, 'great'),
196-
(1, 'fantastic'),
197-
(2, 'thank you'),
198-
(2, 'awesome');
196+
INSERT INTO "comments" ("post_id", "message", "category_id") VALUES
197+
(1, 'great', 3),
198+
(1, 'fantastic', 3),
199+
(2, 'thank you', 3),
200+
(2, 'awesome', 3);
199201

200202
--
201203
-- Data for Name: post_tags; Type: TABLE DATA; Schema: public; Owner: postgres
@@ -388,6 +390,12 @@ ALTER TABLE ONLY "invisibles"
388390

389391
CREATE INDEX comments_post_id_idx ON comments USING btree (post_id);
390392

393+
--
394+
-- Name: comments_category_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
395+
--
396+
397+
CREATE INDEX comments_category_id_idx ON comments USING btree (category_id);
398+
391399

392400
--
393401
-- Name: post_tags_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
@@ -446,6 +454,14 @@ ALTER TABLE ONLY comments
446454
ADD CONSTRAINT comments_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id);
447455

448456

457+
--
458+
-- Name: comments_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
459+
--
460+
461+
ALTER TABLE ONLY comments
462+
ADD CONSTRAINT comments_category_id_fkey FOREIGN KEY (category_id) REFERENCES categories(id);
463+
464+
449465
--
450466
-- Name: post_tags_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
451467
--

tests/fixtures/blog_sqlsrv.sql

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ ALTER TABLE [comments] DROP CONSTRAINT [FK_comments_posts]
4040
END
4141
GO
4242

43+
IF (OBJECT_ID('FK_comments_categories', 'F') IS NOT NULL)
44+
BEGIN
45+
ALTER TABLE [comments] DROP CONSTRAINT [FK_comments_categories]
46+
END
47+
GO
48+
4349
IF (OBJECT_ID('barcodes2', 'U') IS NOT NULL)
4450
BEGIN
4551
DROP TABLE [barcodes2]
@@ -142,6 +148,7 @@ CREATE TABLE [comments](
142148
[id] [bigint] IDENTITY,
143149
[post_id] [int] NOT NULL,
144150
[message] [nvarchar](255) NOT NULL,
151+
[category_id] [int] NOT NULL,
145152
PRIMARY KEY CLUSTERED([id] ASC)
146153
)
147154
GO
@@ -253,14 +260,16 @@ INSERT [categories] ([name], [icon]) VALUES (N'announcement', NULL)
253260
GO
254261
INSERT [categories] ([name], [icon]) VALUES (N'article', NULL)
255262
GO
263+
INSERT [categories] ([name], [icon]) VALUES (N'comment', NULL)
264+
GO
256265

257-
INSERT [comments] ([post_id], [message]) VALUES (1, N'great')
266+
INSERT [comments] ([post_id], [message], [category_id]) VALUES (1, N'great', 3)
258267
GO
259-
INSERT [comments] ([post_id], [message]) VALUES (1, N'fantastic')
268+
INSERT [comments] ([post_id], [message], [category_id]) VALUES (1, N'fantastic', 3)
260269
GO
261-
INSERT [comments] ([post_id], [message]) VALUES (2, N'thank you')
270+
INSERT [comments] ([post_id], [message], [category_id]) VALUES (2, N'thank you', 3)
262271
GO
263-
INSERT [comments] ([post_id], [message]) VALUES (2, N'awesome')
272+
INSERT [comments] ([post_id], [message], [category_id]) VALUES (2, N'awesome', 3)
264273
GO
265274

266275
INSERT [post_tags] ([post_id], [tag_id]) VALUES (1, 1)
@@ -318,6 +327,12 @@ GO
318327
ALTER TABLE [comments] CHECK CONSTRAINT [FK_comments_posts]
319328
GO
320329

330+
ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [FK_comments_categories] FOREIGN KEY([category_id])
331+
REFERENCES [categories] ([id])
332+
GO
333+
ALTER TABLE [comments] CHECK CONSTRAINT [FK_comments_categories]
334+
GO
335+
321336
ALTER TABLE [post_tags] WITH CHECK ADD CONSTRAINT [FK_post_tags_posts] FOREIGN KEY([post_id])
322337
REFERENCES [posts] ([id])
323338
GO

tests/functional/001_records/029_list_example_from_readme_comments_only.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ GET /records/posts?join=comments&filter=id,eq,1
22
===
33
200
44
Content-Type: application/json
5-
Content-Length: 170
5+
Content-Length: 202
66

7-
{"records":[{"id":1,"user_id":1,"category_id":1,"content":"blog started","comments":[{"id":1,"post_id":1,"message":"great"},{"id":2,"post_id":1,"message":"fantastic"}]}]}
7+
{"records":[{"id":1,"user_id":1,"category_id":1,"content":"blog started","comments":[{"id":1,"post_id":1,"message":"great","category_id":3},{"id":2,"post_id":1,"message":"fantastic","category_id":3}]}]}

tests/functional/001_records/031_list_example_from_readme_tags_with_join_path.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ GET /records/posts?join=categories&join=post_tags,tags&join=comments&filter=id,e
22
===
33
200
44
Content-Type: application/json
5-
Content-Length: 378
5+
Content-Length: 410
66

7-
{"records":[{"id":1,"user_id":1,"category_id":{"id":1,"name":"announcement","icon":null},"content":"blog started","post_tags":[{"id":1,"post_id":1,"tag_id":{"id":1,"name":"funny","is_important":false}},{"id":2,"post_id":1,"tag_id":{"id":2,"name":"important","is_important":true}}],"comments":[{"id":1,"post_id":1,"message":"great"},{"id":2,"post_id":1,"message":"fantastic"}]}]}
7+
{"records":[{"id":1,"user_id":1,"category_id":{"id":1,"name":"announcement","icon":null},"content":"blog started","post_tags":[{"id":1,"post_id":1,"tag_id":{"id":1,"name":"funny","is_important":false}},{"id":2,"post_id":1,"tag_id":{"id":2,"name":"important","is_important":true}}],"comments":[{"id":1,"post_id":1,"message":"great","category_id":3},{"id":2,"post_id":1,"message":"fantastic","category_id":3}]}]}

tests/functional/001_records/032_list_example_from_readme.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ GET /records/posts?join=categories&join=tags&join=comments&filter=id,eq,1
22
===
33
200
44
Content-Type: application/json
5-
Content-Length: 318
5+
Content-Length: 350
66

7-
{"records":[{"id":1,"user_id":1,"category_id":{"id":1,"name":"announcement","icon":null},"content":"blog started","post_tags":[{"id":1,"name":"funny","is_important":false},{"id":2,"name":"important","is_important":true}],"comments":[{"id":1,"post_id":1,"message":"great"},{"id":2,"post_id":1,"message":"fantastic"}]}]}
7+
{"records":[{"id":1,"user_id":1,"category_id":{"id":1,"name":"announcement","icon":null},"content":"blog started","post_tags":[{"id":1,"name":"funny","is_important":false},{"id":2,"name":"important","is_important":true}],"comments":[{"id":1,"post_id":1,"message":"great","category_id":3},{"id":2,"post_id":1,"message":"fantastic","category_id":3}]}]}

tests/functional/001_records/034_list_example_from_readme_with_transform_with_exclude.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GET /records/posts?join=categories&join=post_tags,tags&join=comments&exclude=comments.message&filter=id,eq,1
1+
GET /records/posts?join=categories&join=post_tags,tags&join=comments&exclude=comments.message,comments.category_id&filter=id,eq,1
22

33
===
44
200

tests/functional/001_records/038_list_categories_with_binary_content.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GET /records/categories
1+
GET /records/categories?filter=id,le,2
22
===
33
200
44
Content-Type: application/json

tests/functional/001_records/055_filter_category_on_null_icon.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
GET /records/categories?filter=icon,is,null
1+
GET /records/categories?filter=icon,is,null&filter=id,le,2
22
===
33
200
44
Content-Type: application/json
55
Content-Length: 94
66

77
{"records":[{"id":1,"name":"announcement","icon":null},{"id":2,"name":"article","icon":null}]}
88
===
9-
GET /records/categories?filter=icon,is
9+
GET /records/categories?filter=icon,is&filter=id,le,2
1010
===
1111
200
1212
Content-Type: application/json

tests/functional/001_records/068_add_comment_with_sanitation.log

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
POST /records/comments
22

3-
{"user_id":1,"post_id":2,"message":"<h1>Title</h1> <p>Body</p>"}
3+
{"user_id":1,"post_id":2,"message":"<h1>Title</h1> <p>Body</p>","category_id":3}
44
===
55
200
66
Content-Type: application/json
@@ -12,6 +12,6 @@ GET /records/comments/5
1212
===
1313
200
1414
Content-Type: application/json
15-
Content-Length: 43
15+
Content-Length: 59
1616

17-
{"id":5,"post_id":2,"message":"Title Body"}
17+
{"id":5,"post_id":2,"message":"Title Body","category_id":3}

0 commit comments

Comments
 (0)