oimken - 6 months ago

Latest Comment module. in a page twig:

{% include "anomaly.module.comments::comments" with {'subject': page, 'channel': 'waterbowl'} %}

Post comments and approved them in CP is ok, but it just not shows the comments. Got a 404:

GET https://eachage.dev/comments/discussions/read/ 404 ()

I {{ dd(subject.discussion) }} in view anomaly.module.comments::comments.index, Got null so I tried {{ dd(subject) }}, got the correct page model,
but there is no discussion in page model ,
I tried reinstall comment module but no luck.

Please help, thanks a lot!

ryanthompson - 6 months ago

Hmm.. the discussion is started when the first comment is made. What's the comments database table content look like with your test comment?

oimken - 6 months ago

comments_discussions and comments_comments got record and they seems fine.

oimken - 6 months ago

I suspect the problem is the binding did not works in CommentsModuleServiceProvider:

/**
     * Register the addon.
     *
     * @param EloquentModel $model
     */
    public function register(EloquentModel $model)
    {

        $model->bind(
            'discussion',
            function ($channel = 'default') {
                /* @var EloquentModel $this */
                return $this
                    ->morphOne(DiscussionModel::class, 'subject', 'subject_type')
                    ->where('channel', $channel)
                    ->getResults();
            }
        );

        $model->bind(
            'discussions',
            function () {
                /* @var EloquentModel $this */
                return $this
                    ->morphMany(DiscussionModel::class, 'subject', 'subject_type');
            }
        );

        $model->bind(
            'get_discussions',
            function () {
                /* @var EloquentModel $this */
                return $this->discussions->getResults();
            }
        );
    }

but I do not know how to debug this...

oimken - 6 months ago

I just try {{ dd(subject.discussions()) }}
Finally I got returns :

MorphMany {#25797 ▼
  #morphType: "comments_discussions.subject_type"
  #morphClass: "Anomaly\PagesModule\Page\PageModel"
  #foreignKey: "comments_discussions.subject_id"
  #localKey: "id"
  #query: EntryQueryBuilder {#25787 ▶}
  #parent: PageModel {#12410 ▶}
  #related: DiscussionModel {#25749 ▶}
}

oimken - 6 months ago

Ok, I don't know why ,
when I change another channel name...
and post some new comments ....
It seems work fine now
Thanks for your help, Ryan!