[Coldbox 6.x] - Easy way to get the next record in the query

Hi,

I am using CBORM and I have a query that returns the current blog post using this syntax:

  prc.post = ormService.findWhere(entityName="BlogPost", criteria={articleSlug=#rc.slug#});

I am wanting to get the “next post” after this based on the date published field. After the above line I have this line which returns all the active blog posts sorted by date published descending (including the one above).

prc.blogposts = ormService.list(entityName="BlogPost",active=1,asQuery=true, sortOrder="datePublished desc");

Maybe there is another way to go about this but I am trying to return information about the “next” post in the result set. Is there a way to do this using any native coldbox methods or maybe I should rethink how to do this altogether? I essentially want to get the current row + 1, but I am not quite sure how to do this give I am using CBORM.

Thanks in advance!

You could add a couple of where filters (restrictions?) to specify the blog post should be:

  1. publishedDate greater than the current post
  2. Not the same ID as the current post
  3. Limit of 1.
    I would probably use a criteria query for this, as you can get access to those restrictions easily.