Team-Tea-Time / laravel-forum

A slim, lean forum package designed for quick and easy integration in Laravel projects
https://laravel-forum.teamteatime.net/
MIT License
601 stars 165 forks source link

Post Order by Update Date #137

Closed m3rg closed 8 years ago

m3rg commented 8 years ago

Steps:

  1. Create a new thread.
  2. Write some new posts.
  3. Edit the first thread post.
  4. Thread post is now displayed at last.

I think create date order should be preserved.

Riari commented 8 years ago

Unable to reproduce. Posts are displayed in order of created_at, not updated_at, and only the latter is changed when editing a post.

m3rg commented 8 years ago

I checked Models/Thread.php line 83 and I don't see any query ordering. I mean this part which is used displaying the posts of a thread:

    public function posts()
    {
        $withTrashed = config('forum.preferences.display_trashed_posts') || Gate::allows('viewTrashedPosts');
        $query = $this->hasMany(Post::class);
        return $withTrashed ? $query->withTrashed() : $query;
    }

Am I missing something? Because it's not sorting anything. I am using postgresql which is probably changing the internal order after an update. Do you think this might be the problem that you couldn't reproduce?

Riari commented 8 years ago

My mistake. You're right, there is no ordering, not even in the postsPaginated attribute. I suspect you're right about postgres too. I'll think about where to apply the ordering since the posts relationship itself is used for retrieving the first and last posts of the thread as well, so I would rather leave that as is.

Riari commented 8 years ago

Fix included in new release.