yii2mod / yii2-comments

Comments module for Yii2
MIT License
159 stars 64 forks source link

Is there a way to getChildren works with orderBy #62

Closed carlosgarcia8 closed 7 years ago

carlosgarcia8 commented 7 years ago

I would like to see the replies of a comment with the oldest at first and the newer at the bottom, like youtube. Is it possible? By default it works the other way around.

Example: carlos -- Hii 2 days ago anonymous -- Bye 1 day ago masteroftea -- Haha 1 minute ago

ihorchepurnyi commented 7 years ago

Hi, by default I have the following order of comments - link

All oldest replies of comments at first

carlosgarcia8 commented 7 years ago

Thats how I would like it to be, but this is what Im getting - link

ihorchepurnyi commented 7 years ago

You need to create your own CommentModel and override getTree method with the custom sorting

ihorchepurnyi commented 7 years ago

What MySQL version do you use?

carlosgarcia8 commented 7 years ago

I am using PostgreSQL 9.5.6, so I need to override the CommentModel, use the yii2mod\comments\models\CommentModel as the base and extends from it, then override the getTree to make my custom sorting, right?

ihorchepurnyi commented 7 years ago

yes, you right. After that, you need to override commentModelClass in the CommetModule by the following code:

'modules' => [
    'comment' => [
        'class' => 'yii2mod\comments\Module',
        'commentModelClass' =>  'path to your custom CommentModel',
    ],
]
carlosgarcia8 commented 7 years ago

Okay, Thank you for your answers. By the way, the problem that your default sort is different than mine is because I use postgresql and you mysql? That makes no sense to me

ihorchepurnyi commented 7 years ago

I agree with you, but I don't know why comments in our projects have different sorting.

carlosgarcia8 commented 7 years ago

Well, I'm going to override it and work on it and if I find out why we have different sorting I'll let you know.

ihorchepurnyi commented 7 years ago

Ok, thanks!

ihorchepurnyi commented 7 years ago

I added order to getTree. Can you update your package to dev-master version and check it again?

carlosgarcia8 commented 7 years ago

Yea this way it works as it has to!

ihorchepurnyi commented 7 years ago

Cool, thanks!