Skip to content

Commit 6a9c366

Browse files
bpamiriclaude
andcommitted
fix: Remove PostStatus/PostType INNER JOINs that break on CockroachDB IDs
The post_statuses seed migration lacks explicit IDs, so CockroachDB assigns large unique_rowid() values. But blogStatuses() hardcodes {POSTED=2, ...} and blog approval sets statusId=2, which matches no actual post_statuses row. The include="PostStatus" INNER JOIN then excludes every blog, causing show() to redirect to the list page. Remove PostStatus and PostType from all include= clauses and use the text status column in views instead of the association. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d6d2226 commit 6a9c366

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

app/controllers/Controller.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ component extends="wheels.Controller" {
105105
return model("Blog").findOne(
106106
where="blog_posts.slug = :slug AND blog_posts.status = 'Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= :now",
107107
params={slug={value=arguments.slug, cfsqltype="cf_sql_varchar"}, now={value=now(), cfsqltype="cf_sql_timestamp"}},
108-
include="User,PostStatus",
108+
include="User",
109109
cache=10
110110
);
111111
}

app/controllers/admin/AdminController.cfc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ component extends="app.Controllers.Controller" {
2121
public void function editBlog() {
2222
try {
2323
// Get the blog post
24-
var blog = model("Blog").findByKey(key=params.id, include="User,PostStatus");
24+
var blog = model("Blog").findByKey(key=params.id, include="User");
2525

2626
// Check if blog exists
2727
if (!isObject(blog)) {
@@ -410,7 +410,7 @@ component extends="app.Controllers.Controller" {
410410
private function getBlogBySlug(required string slug) {
411411
return model("Blog").findOne(
412412
where="blog_posts.slug = '#arguments.slug#'",
413-
include="User,PostStatus"
413+
include="User"
414414
);
415415
}
416416

@@ -606,7 +606,7 @@ component extends="app.Controllers.Controller" {
606606

607607
public function getAllBlogs() {
608608
return model("Blog").findAll(
609-
include="User, PostStatus, PostType",
609+
include="User",
610610
order="createdAt DESC",
611611
options={
612612
sql="

app/controllers/web/BlogController.cfc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ component extends="app.Controllers.Controller" {
258258
}
259259

260260
// Get the blog post
261-
blog = model("Blog").findByKey(key = params.id, include = "User,PostStatus");
261+
blog = model("Blog").findByKey(key = params.id, include = "User");
262262

263263
// Check if blog exists
264264
if (!IsObject(blog)) {
@@ -376,15 +376,15 @@ component extends="app.Controllers.Controller" {
376376
var query = model("blog").findAll(
377377
where = "blog_posts.status ='Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#Now()#' AND (blog_posts.slug LIKE :pattern OR blog_posts.title LIKE :pattern OR blog_posts.content LIKE :pattern OR fullname LIKE :pattern OR email LIKE :pattern)",
378378
params = {pattern={value=searchPattern, cfsqltype="cf_sql_varchar"}},
379-
include = "User, PostStatus, PostType",
379+
include = "User",
380380
order = "publishedAt DESC",
381381
page = page,
382382
perPage = perPage
383383
);
384384

385385
if (isInfiniteScroll) {
386386
totalCount = model("blog").count(
387-
include = "User, PostStatus, PostType",
387+
include = "User",
388388
where = "blog_posts.status ='Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.publishedAt <= '#Now()#' AND (blog_posts.slug LIKE :pattern OR blog_posts.title LIKE :pattern OR blog_posts.content LIKE :pattern OR fullname LIKE :pattern OR email LIKE :pattern)",
389389
params = {pattern={value=searchPattern, cfsqltype="cf_sql_varchar"}}
390390
);
@@ -995,7 +995,7 @@ component extends="app.Controllers.Controller" {
995995
}
996996

997997
private function getBlogById(required numeric id) {
998-
return model("Blog").findOne(where = "blog_posts.id = #arguments.id#", include = "User, PostStatus");
998+
return model("Blog").findOne(where = "blog_posts.id = #arguments.id#", include = "User");
999999
}
10001000

10011001
private function saveBlog(required struct blogData) {

app/views/admin/AdminController/showBlog.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
hx-target=".main"
6363
<!--- hx-vals='{"category_id": "#blog.Category.id#"}' --->
6464
>
65-
#blog.PostStatus.name# in <span class="text--primary">#categoryList#</span>
65+
#blog.status# in <span class="text--primary">#categoryList#</span>
6666
</p>
6767
<p class="fw-medium fs-12 text--lightGray">Tags: <span class="text--primary">#tagList#</span></p>
6868
</div>

app/views/web/BlogController/show.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<!-- Post status + Categories -->
6262
<cfif categories.recordCount GT 0>
6363
<p class="fw-medium fs-12 text--lightGray mb-0">
64-
#blog.PostStatus.name# in
64+
#blog.status# in
6565
<cfoutput query="categories">
6666
<strong
6767
class="text--primary"

0 commit comments

Comments
 (0)