Problem/Motivation
When sorting by cid, the comments are out of order. The site was a Drupal 7 site migrated to D9 that had an issue with the cid orders not corresponding with creation date. Because the cid's are inherently out of order, using cid as a sort order does not work. I need to use creation date (c.created) instead.
Proposed resolution
Add option to sort by "created" instead of "cid."
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | issue-3301217.patch | 3.31 KB | lobodakyrylo |
Comments
Comment #2
lobodakyrylo commentedThere is no way to order comments by creation date using this module. The cid field is an auto increment field that's always correspond to creation date order. It means, that the first comment will have cid as 1 and the second as 2. The cid field is used for ordering because if you select group comments by threads, comments will be sorted by the thread field, that also contains all the ancestor comment ids. This method is used also in Drupal core. If we change 'cid' to 'created' only for non-thread comment order, it will break the philosophy of core comment ordering.
Drupal 7 has the same logic of 'cid' and 'thread' fields so I suggest to re-migrate comments from D7 to keep all the right cid ordering. BTW, I created this module when I migrated my website from D7 to D8 with lots of comments with threads and it worked.
Comment #3
benfreda commentedThanks for the reply!
Unfortunately, in this case, cid just isn't a good sorting option for me. For some reason, the cids are not in the correct order. I'll give you an example. A working comments section should look like the following:
Comment 1 - posted January 1, 2022 (cid 1)
Comment 2 - posted January 2, 2022 (cid 2)
Comment 3 - posted January 3, 2022 (cid 3)
Comment 4 - posted January 4, 2022 (cid 4)
Comment 5 - posted January 5, 2022 (cid 5)
However, for some reason, this is what I'm actually getting on some comment sections:
Comment 1 - posted January 1, 2022 (cid 1)
Comment 2 - posted January 2, 2022 (cid 5)
Comment 3 - posted January 3, 2022 (cid 4)
Comment 4 - posted January 4, 2022 (cid 2)
Comment 5 - posted January 5, 2022 (cid 3)
There are later posts with smaller cids. There's no way a post from 2022 was written before a post from 2020 - but that's what the database thinks is happening. From what I can tell, this is a very old problem that started well before I started work on this particular site. I don't know of a safe way to adjust the cids, especially because this particular site has so many comments. I know your module has no current ability to sort by creation date, but I was hoping there was a way to accomplish this, since, in the circumstances, the cids are not a reliable mechanism.
Comment #4
lobodakyrylo commentedTry to use this patch. It adds "Order by Authored On field" checkbox for flat orders (without threading) and this do what you need. Please, confirm that is working then I'll be able to apply it to new release.
Comment #5
benfreda commentedThe patch does, indeed, work! Can't thank you enough for your help on this.
Comment #7
lobodakyrylo commentedAdded to 3.0.1 release.
Comment #8
lobodakyrylo commented