-
Notifications
You must be signed in to change notification settings - Fork 206
getPosts Helper: sortBy not working #104
Comments
This should work as expected, since A couple things to check:
Thanks for helping troubleshoot this.
It looks like this helper doesn't support the |
At first I have to say, that I'm completely new to Javascript, Node and Postleaf. So don't be angry if I'm doing or saying stupid things ;)
No. I've checked the database and all dates are different
No errors.
I figured out, that if i use a sort order other then "title", i will end up in the catch-block. I've put a debug message there. If i use "title" the then-block is processed. Knowing this, i removed the catch and got the following, database-releated error in the console:
Maybe there is something wrong with my database? I will try it with a clean one... |
The error also occurs with a newly generated databse. |
I think, i've got it. I enabled logging in database.js, took the error causing SQL-Statement and put it into my SQLite Debugger. That shows, that there was a missing table identifier in the second ORDER BY. So i changed it to
and the result was like expected. But I have no idea how to fix this in postleaf...
|
Ah, Try swapping this with this: [sequelize.fn('lower', sequelize.literal('post.createdAt'), sortOrder] If that works as intended, we can rework the logic to account for it. |
Cory, that works fine! I tried your modification and after successfully testing ist, i changed this line to this |
I don't believe it affects the other helpers. This happens because we're including the user and that join creates two Feel free to submit a PR for the fix you suggested. |
Table identifier is necessary in this helper, because 'user' is included. That makes and some(?) database rows ambiguous Postleaf#104
Fixed in #106 |
Summary
I want to link the last created post to a logo at the homepage. So i try to get this very last post with the following lines of code at the end of blog.dust:
This returns nothing! Not even the text "no posts yet!" is displayed. So i changed the
sortBy
Parameter back to"title"
and got the expected result: one post with a leading "Z" in title is shown.Then i tried the other sortBy-Values as described in {@getPosts} and figured out, that none of them is working as expected. Only
"title"
and any value, not defined in theme_helpers.js:442 will work.What am I doing wrong? Or is it a bug?
Steps to Reproduce
{/body}
Additional feature request
It would be cool if sorting would be possible for
publishedAt
, also. And a filter forisPublished
would be nice. Saying that... what about an{@getLastPost}
helper ;)The text was updated successfully, but these errors were encountered: