Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit 09ff07e

Browse files
committed
wip
1 parent 4dbd48b commit 09ff07e

1 file changed

Lines changed: 69 additions & 1 deletion

File tree

public/miscellaneous/debug-blog.cfm

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,75 @@ if (q4.recordCount > 0) {
8484
writeOutput(" user #q4.id# (#q4.first_name#) deletedat: [#isNull(q4.deletedat) ? 'NULL' : q4.deletedat#]" & chr(10));
8585
}
8686
87-
// 5. Check deletedat NULL vs empty string
87+
// 5. Test the exact kind of query Wheels ORM would generate
88+
writeOutput(chr(10) & "=== Simulating Wheels ORM generated SQL ===" & chr(10));
89+
90+
// Wheels generates INNER JOINs for belongsTo with include=
91+
// and adds deletedat IS NULL for soft-delete on all joined tables
92+
try {
93+
q_wheels = queryExecute("
94+
SELECT blog_posts.id, blog_posts.title, blog_posts.slug
95+
FROM blog_posts
96+
INNER JOIN users ON users.id = blog_posts.created_by
97+
INNER JOIN post_statuses ON post_statuses.id = blog_posts.status_id
98+
WHERE blog_posts.slug = :slug
99+
AND blog_posts.status = 'Approved'
100+
AND blog_posts.is_published = 'true'
101+
AND blog_posts.deletedat IS NULL
102+
AND users.deletedat IS NULL
103+
AND post_statuses.deletedat IS NULL
104+
LIMIT 1
105+
", { slug: slug }, { datasource: TARGET_DS });
106+
writeOutput(" Full simulated query: #q_wheels.recordCount# rows" & chr(10));
107+
if (q_wheels.recordCount > 0) {
108+
writeOutput(" id=#q_wheels.id# title=#q_wheels.title#" & chr(10));
109+
}
110+
} catch (any e) {
111+
writeOutput(" ERROR: #e.message#" & chr(10));
112+
if (len(e.detail)) writeOutput(" Detail: #e.detail#" & chr(10));
113+
}
114+
115+
// Test each condition incrementally
116+
writeOutput(chr(10) & "=== Testing conditions one by one ===" & chr(10));
117+
conditions = [
118+
"blog_posts.deletedat IS NULL",
119+
"blog_posts.status = 'Approved'",
120+
"blog_posts.is_published = 'true'",
121+
"users.deletedat IS NULL",
122+
"post_statuses.deletedat IS NULL"
123+
];
124+
accumulated = "blog_posts.slug = '#slug#'";
125+
for (cond in conditions) {
126+
accumulated &= " AND " & cond;
127+
try {
128+
qtest = queryExecute("
129+
SELECT count(*) as cnt
130+
FROM blog_posts
131+
INNER JOIN users ON users.id = blog_posts.created_by
132+
INNER JOIN post_statuses ON post_statuses.id = blog_posts.status_id
133+
WHERE #accumulated#
134+
", {}, { datasource: TARGET_DS });
135+
writeOutput(" + #cond# => #qtest.cnt# rows" & chr(10));
136+
} catch (any e) {
137+
writeOutput(" + #cond# => ERROR: #e.message#" & chr(10));
138+
}
139+
}
140+
141+
// 5b. Test via Wheels framework if available
142+
writeOutput(chr(10) & "=== Testing via Wheels ORM (if available) ===" & chr(10));
143+
try {
144+
testBlog = application.wheels.models.Blog.$findAll(
145+
where="blog_posts.slug = '#slug#' AND status ='Approved' AND isPublished='true' ",
146+
include="User,PostStatus",
147+
returnAs="query",
148+
maxRows=1
149+
);
150+
writeOutput(" Wheels ORM returned: #testBlog.recordCount# rows" & chr(10));
151+
} catch (any e) {
152+
writeOutput(" Not available or error: #e.message#" & chr(10));
153+
}
154+
155+
// 6. Check deletedat NULL vs empty string
88156
writeOutput(chr(10) & "=== deletedat NULL check ===" & chr(10));
89157
q5a = queryExecute("
90158
SELECT count(*) as cnt FROM blog_posts WHERE deletedat IS NULL

0 commit comments

Comments
 (0)