GithubHelp home page GithubHelp logo

Comments (8)

claviska avatar claviska commented on May 18, 2024

This should work as expected, since createdAt is a valid option. If not it's likely a bug.

A couple things to check:

  1. Are your createdAt dates all the same?
  2. Are you seeing any errors in the Node console?
  3. If you log the result,
    are you seeing an empty array or something else?

Thanks for helping troubleshoot this.

This returns nothing! Not even the text "no posts yet!" is displayed.

It looks like this helper doesn't support the {:else} block as documented. That would explain why you're not seeing "no posts yet!". I've discovered a few more helpers that this affects and opened a new issue (see #105).

from postleaf.

M8inC avatar M8inC commented on May 18, 2024

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 ;)

Are your createdAt dates all the same?

No. I've checked the database and all dates are different

Are you seeing any errors in the Node console?

No errors.

If you log the result, are you seeing an empty array or something else?

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:

Unhandled rejection SequelizeDatabaseError: SQLITE_ERROR: ambiguous column name: createdAt
    at Query.formatError (/var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/dialects/sqlite/query.js:348:14)
    at afterExecute (/var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/dialects/sqlite/query.js:112:29)
    at replacement (/var/web/ohnemotor.de/dev/postleaf/node_modules/sqlite3/lib/trace.js:19:31)
    at Statement.errBack (/var/web/ohnemotor.de/dev/postleaf/node_modules/sqlite3/lib/sqlite3.js:16:21)
From previous event:
    at executeSql (/var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/dialects/sqlite/query.js:103:19)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)
From previous event:
    at Promise.then (/var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/promise.js:21:17)
    at Database.<anonymous> (/var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/dialects/sqlite/query.js:278:14)
    at /var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/dialects/sqlite/query.js:98:19
From previous event:
    at Query.run (/var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/dialects/sqlite/query.js:96:13)
    at /var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/sequelize.js:849:20
    at /var/web/ohnemotor.de/dev/postleaf/node_modules/retry-as-promised/index.js:39:21
From previous event:
    at retryAsPromised (/var/web/ohnemotor.de/dev/postleaf/node_modules/retry-as-promised/index.js:29:10)
    at /var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/sequelize.js:848:12
From previous event:
    at Promise.then (/var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/promise.js:21:17)
    at Model.findAll (/var/web/ohnemotor.de/dev/postleaf/node_modules/sequelize/lib/model.js:1395:6)
    at chunk.map (/var/web/ohnemotor.de/dev/postleaf/source/modules/helpers/theme_helpers.js:451:10)
    at Chunk.map (/var/web/ohnemotor.de/dev/postleaf/node_modules/dustjs-linkedin/lib/dust.js:722:7)
    at Object.dust.helpers.getPosts (/var/web/ohnemotor.de/dev/postleaf/source/modules/helpers/theme_helpers.js:421:18)
    at Chunk.helper (/var/web/ohnemotor.de/dev/postleaf/node_modules/dustjs-linkedin/lib/dust.js:928:33)
    at body_1 (evalmachine.<anonymous>:1:1301)
    at Chunk.block (/var/web/ohnemotor.de/dev/postleaf/node_modules/dustjs-linkedin/lib/dust.js:881:14)
    at body_0 (evalmachine.<anonymous>:1:1291)
    at done (/var/web/ohnemotor.de/dev/postleaf/node_modules/dustjs-linkedin/lib/dust.js:176:13)
    at Fs.readFile (/var/web/ohnemotor.de/dev/postleaf/source/modules/dust_engine.js:62:7)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

Maybe there is something wrong with my database? I will try it with a clean one...

from postleaf.

M8inC avatar M8inC commented on May 18, 2024

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.

from postleaf.

M8inC avatar M8inC commented on May 18, 2024

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

ORDER BY lower(`post`.`createdAt`) DESC;

and the result was like expected. But I have no idea how to fix this in postleaf...

SELECT `post`.*, `author`.`id` AS `author.id`, `author`.`name` AS `author.name`, `author`.`email` AS `author.email`, 
`author`.`username` AS `author.username`, `author`.`role` AS `author.role`, 
`author`.`avatar` AS `author.avatar`, `author`.`image` AS `author.image`, `author`.`location` AS `author.location`, `author`.`bio` AS `author.bio`, 
`author`.`website` AS `author.website`, `author`.`createdAt` AS `author.createdAt`, `author`.`updatedAt` AS `author.updatedAt`, 
`tags`.`id` AS `tags.id`, `tags`.`slug` AS `tags.slug`, `tags`.`name` AS `tags.name`, `tags`.`description` AS `tags.description`, 
`tags`.`image` AS `tags.image`, `tags`.`metaTitle` AS `tags.metaTitle`, `tags`.`metaDescription` AS `tags.metaDescription`, `tags`.`createdAt` AS `tags.createdAt`, 
`tags`.`updatedAt` AS `tags.updatedAt`, `tags.postTags`.`createdAt` AS `tags.postTags.createdAt`, `tags.postTags`.`updatedAt` AS `tags.postTags.updatedAt`, 
`tags.postTags`.`postId` AS `tags.postTags.postId`, `tags.postTags`.`tagId` AS `tags.postTags.tagId` 
FROM (
SELECT `post`.`id`, `post`.`slug`, `post`.`userId`, `post`.`publishedAt`, `post`.`title`, `post`.`content`, `post`.`image`, `post`.`metaTitle`, 
`post`.`metaDescription`, `post`.`template`, `post`.`status`, `post`.`isPage`, `post`.`isFeatured`, `post`.`isSticky`, `post`.`createdAt`, `post`.`updatedAt` 
FROM `posts` AS `post` ORDER BY lower(`createdAt`) DESC LIMIT 0, '1') AS `post` 
LEFT OUTER JOIN `users` AS `author` ON `post`.`userId` = `author`.`id` 
LEFT OUTER JOIN `postTags` AS `tags.postTags` ON `post`.`id` = `tags.postTags`.`postId` 
LEFT OUTER JOIN `tags` AS `tags` ON `tags`.`id` = `tags.postTags`.`tagId` ORDER BY lower(`post`.`createdAt`) DESC;

from postleaf.

claviska avatar claviska commented on May 18, 2024

Ah, createdAt is ambiguous in that query. Thanks for narrowing this down.

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.

from postleaf.

M8inC avatar M8inC commented on May 18, 2024

Cory, that works fine! I tried your modification and after successfully testing ist, i changed this line to this
sortBy = 'post.' + ((sortBy || '').match(/^(id|slug|title|createdAt)$/) ? sortBy : 'title');
to address this issue. Is this the right way to do this? I could check all other helpers add the missing table identifier?!

from postleaf.

claviska avatar claviska commented on May 18, 2024

I don't believe it affects the other helpers. This happens because we're including the user and that join creates two createdAt fields. It looks like getPosts is the only helper that does this.

Feel free to submit a PR for the fix you suggested.

from postleaf.

claviska avatar claviska commented on May 18, 2024

Fixed in #106

from postleaf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.