@@ -118,8 +118,8 @@ component extends="app.Controllers.Controller" {
118118 // Try to get both stats in one query if your database supports it
119119 try {
120120 return {
121- " totalPosts" : model (" Blog" ).count (where = " createdBy = #val ( arguments .authorId ) #" ),
122- " totalComments" : model (" Comment" ).count (where = " authorId = #val ( arguments .authorId ) #" )
121+ " totalPosts" : model (" Blog" ).count (where = " createdBy = #arguments .authorId #" ),
122+ " totalComments" : model (" Comment" ).count (where = " authorId = #arguments .authorId #" )
123123 };
124124 } catch (any e ) {
125125 model (" Log" ).log (
@@ -221,8 +221,8 @@ component extends="app.Controllers.Controller" {
221221 // Get categories and tags for the form
222222 categories = model (" Category" ).findAll (order = " name ASC" );
223223 postTypes = model (" PostType" ).findAll (order = " name ASC" );
224- var blogCategories = model (" BlogCategory" ).findAll (where = " blogId = #val ( blog .id ) #" );
225- var blogTags = model (" Tag" ).findAll (where = " blogId = #val ( blog .id ) #" );
224+ var blogCategories = model (" BlogCategory" ).findAll (where = " blogId = #blog .id #" );
225+ var blogTags = model (" Tag" ).findAll (where = " blogId = #blog .id #" );
226226
227227 // Prepare data for the view
228228 var selectedCategories = [];
@@ -264,7 +264,7 @@ component extends="app.Controllers.Controller" {
264264 private function getBlogsByAuthor (required authorId , numeric page = 1 , numeric perPage = 6 , boolean isInfiniteScroll = false ) {
265265 var result = {
266266 query = model (" Blog" ).findAll (
267- where = " blog_posts.statusId <> 1 AND blog_posts.status = 'Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.createdBy = #val ( arguments .authorId ) #" ,
267+ where = " blog_posts.statusId <> 1 AND blog_posts.status = 'Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.createdBy = #arguments .authorId #" ,
268268 include = " User" ,
269269 order = " COALESCE(post_created_date, blog_posts.createdat) DESC" ,
270270 page = arguments .page ,
@@ -275,7 +275,7 @@ component extends="app.Controllers.Controller" {
275275 };
276276
277277 result .totalCount = model (" Blog" ).count (
278- where = " blog_posts.statusId <> 1 AND blog_posts.status = 'Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.createdBy = #val ( arguments .authorId ) #"
278+ where = " blog_posts.statusId <> 1 AND blog_posts.status = 'Approved' AND blog_posts.publishedAt IS NOT NULL AND blog_posts.createdBy = #arguments .authorId #"
279279 );
280280 result .hasMore = (page * perPage ) < result .totalCount ;
281281
@@ -648,7 +648,7 @@ component extends="app.Controllers.Controller" {
648648 var whereClause = " title = '#form .title #'" ;
649649
650650 if (structKeyExists (form , " id" ) && isNumeric (form .id ) && form .id > 0 ) {
651- whereClause & = " AND id != #val ( form .id ) #" ;
651+ whereClause & = " AND id != #form .id #" ;
652652 }
653653
654654 var blogModel = model (" Blog" ).findAll (where = whereClause );
@@ -857,15 +857,15 @@ component extends="app.Controllers.Controller" {
857857 if (! isObject (category )) return {query = queryNew (" " ), hasMore = false , totalCount = 0 };
858858
859859 var blogCategoryQuery = model (" BlogCategory" )
860- .findAll (where = " categoryId = #val ( category .id ) #" , returnAs = " query" );
860+ .findAll (where = " categoryId = #category .id #" , returnAs = " query" );
861861 if (blogCategoryQuery .recordCount == 0 ) return {query = queryNew (" " ), hasMore = false , totalCount = 0 };
862862
863863 var blogIds = blogCategoryQuery .columnData (" blogId" );
864864 var blogIdList = arrayToList (blogIds );
865865
866866 var result = {
867867 query = model (" Blog" ).findAll (
868- where = " blog_posts.id IN (#blogIdList #) AND categoryId = #val ( category .id ) # AND blog_posts.status ='Approved' AND blog_posts.publishedAt IS NOT NULL" ,
868+ where = " blog_posts.id IN (#blogIdList #) AND categoryId = #category .id # AND blog_posts.status ='Approved' AND blog_posts.publishedAt IS NOT NULL" ,
869869 order = " createdAt DESC" ,
870870 include = " User,BlogCategory" ,
871871 returnAs = " query" ,
@@ -877,7 +877,7 @@ component extends="app.Controllers.Controller" {
877877 };
878878
879879 result .totalCount = model (" Blog" ).count (
880- where = " blog_posts.id IN (#blogIdList #) AND categoryId = #val ( category .id ) # AND blog_posts.status ='Approved' AND blog_posts.publishedAt IS NOT NULL" ,
880+ where = " blog_posts.id IN (#blogIdList #) AND categoryId = #category .id # AND blog_posts.status ='Approved' AND blog_posts.publishedAt IS NOT NULL" ,
881881 include = " User,BlogCategory"
882882 );
883883 result .hasMore = (page * perPage ) < result .totalCount ;
@@ -908,7 +908,7 @@ component extends="app.Controllers.Controller" {
908908
909909 private function getBlogById (required numeric id ) {
910910 return model (" Blog" ).findOne (
911- where = " blog_posts.id = #val ( arguments .id ) #" ,
911+ where = " blog_posts.id = #arguments .id #" ,
912912 include = " User, PostStatus"
913913 );
914914 }
@@ -993,7 +993,18 @@ component extends="app.Controllers.Controller" {
993993 }
994994 newBlog .save ();
995995
996- response .blogId = newBlog .id ;
996+ // Retrieve the generated ID by looking up the just-created blog by slug.
997+ // Wheels' PostgreSQL adapter does not always return the auto-generated
998+ // primary key after INSERT (e.g. when the column uses a BIGINT default
999+ // or trigger-based ID generation rather than SERIAL).
1000+ if (! len (trim (newBlog .id ))) {
1001+ var createdBlog = model (" Blog" ).findOne (where = " slug = '#blogData .slug #'" );
1002+ if (isObject (createdBlog )) {
1003+ response .blogId = createdBlog .id ;
1004+ }
1005+ } else {
1006+ response .blogId = newBlog .id ;
1007+ }
9971008 response .message = " Blog post created successfully." ;
9981009 } else {
9991010 response .message = " A blog post with the same title already exists." ;
@@ -1056,7 +1067,7 @@ component extends="app.Controllers.Controller" {
10561067 }
10571068
10581069 function getAllCommentsByBlogid (required numeric id ) {
1059- var comments = model (" Comment" ).findAll (include = " User" , where = " isPublished = 1 AND blogid = #val ( arguments .id ) # AND commentParentId IS NULL" , cache = 5 );
1070+ var comments = model (" Comment" ).findAll (include = " User" , where = " isPublished = 1 AND blogid = #arguments .id # AND commentParentId IS NULL" , cache = 5 );
10601071
10611072 return comments ;
10621073 }
@@ -1106,7 +1117,7 @@ component extends="app.Controllers.Controller" {
11061117 response = saveComment (params );
11071118 }
11081119 if (structKeyExists (response , " Id" )){
1109- comments = commentModel .findAll (include = " User" , where = " id = #val ( response .Id ) # AND isPublished = 1" );
1120+ comments = commentModel .findAll (include = " User" , where = " id = #response .Id # AND isPublished = 1" );
11101121 renderPartial (partial = " partials/comment" );
11111122 }
11121123 } catch (any e ) {
@@ -1172,7 +1183,7 @@ component extends="app.Controllers.Controller" {
11721183 throw (" Invalid blog ID" , " InvalidRequest" );
11731184 }
11741185
1175- var blogId = val ( params .id ) ;
1186+ var blogId = params .id ;
11761187 var blog = model (" Blog" ).findByKey (blogId );
11771188 var user = model (" User" ).findByKey (currentUserId );
11781189
0 commit comments