XF 2.3 Scratch Pad Tutorial - Reactions error : LogicException: Unknown relation or alias accessed

Basenotes

Well-known member
Hello, I've been following Kier's tutorial and have got to the part on reactions. I am able to react to an item, however it does't show on page reload (though it is stored in the database)

When I click to see who has reacted, I get this error (I'm using Basenotes\Reviews:Review instead of Demo\Pad:Note):


LogicException: Unknown relation or alias Basenotes\Reviews:Review accessed on xf_bn_reviews in src/XF/Mvc/Entity/Finder.php at line 790
  1. XF\Mvc\Entity\Finder->join() in src/XF/Mvc/Entity/Finder.php at line 672
  2. XF\Mvc\Entity\Finder->with() in src/XF/Mvc/Entity/Manager.php at line 223
  3. XF\Mvc\Entity\Manager->findByIds() in src/XF/App.php at line 3240
  4. XF\App->findByContentType() in src/XF/Reaction/AbstractHandler.php at line 372
  5. XF\Reaction\AbstractHandler->getContent() in src/XF/Repository/ReactionRepository.php at line 369
  6. XF\Repository\ReactionRepository->addContentToReactions() insrc/XF/ControllerPlugin/ReactionPlugin.php at line 201
  7. XF\ControllerPlugin\ReactionPlugin->actionReactions() insrc/addons/Basenotes/Reviews/Pub/Controller/Review.php at line 202
  8. Basenotes\Reviews\Pub\Controller\Review->actionReactions() in src/XF/Mvc/Dispatcher.php at line362
  9. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 264
  10. XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
  11. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
  12. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2826
  13. XF\App->run() in src/XF.php at line 806
  14. XF::runApp() in index.php at line 23


Bit's of code I think might be relevant:

src/addons/Basenotes/Reviews/Reaction/Review.php

PHP:
<?php

namespace Basenotes\Reviews\Reaction;

use XF\Mvc\Entity\Entity;
use XF\Reaction\AbstractHandler;

/**
 */
class Review extends AbstractHandler
{
    public function reactionsCounted(Entity $entity)
    {
        return ($entity->message_state == 'visible');
    }

    public function getEntityWith()
    {
        return ['Basenotes\Reviews:Review', 'Basenotes\Reviews:Review.User'];
    }
}

src/addons/Basenotes/Reviews/Entity/Review.php (snippet)

Code:
   use ReactionTrait;

    public function canReact(&$error = null)
    {

return true;
    }

src/addons/Basenotes/Reviews/Pub/Controller/Review.php (snippet)

PHP:
public function actionReact(ParameterBag $params)
{
    $review = $this->assertViewableReview($params->review_id);

 $reactionPlugin = $this->plugin('XF:Reaction');
  return $reactionPlugin->actionReactSimple($review, 'reviews');



}

public function actionReactions(ParameterBag $params){

        $review = $this->assertViewableReview($params->review_id);


    $reactionPlugin = $this->plugin('XF:Reaction');
        return $reactionPlugin->actionReactions($review, 'reviews/reactions', null, []);

}


protected function assertViewableReview($id, $with=null, $phraseKey=null)
{

  $review = $this->assertReviewExists($id, $with, $phraseKey);

  if (!$review->canView($error))
  {

throw $this->exception(

    $this->noPermission($error)

);


  }
    return $review;


}


admin.php?content-types/

Screenshot 2025-05-12 at 10.49.36.webp

Screenshot 2025-05-12 at 10.49.50.webp



Apologies if this is all obvious stuff, although I've been coding php for about 20 years, it's always been procedural as I've never got my head round OOP sadly
 
In your \Basenotes\Reviews\Reaction\Review::getEntityWith method, you should return an array of relations to eager-load when displaying reactions (by their relation key, not entity name). I don't know what those are without seeing your entity structure or how it handles permission, but as a blind guess you might want ['User'] or even nothing at all ([]).
 
Last edited:
In your \Basenotes\Reviews\Reaction\Review::getEntityWith method, you should return an array of relations to eager-load when displaying reactions (by their relation key, not entity name). I don't know what those are without seeing your entity structure or how it handles permission, but as a blind guess you might want ['User'] or even nothing at all ([]).

Thank you for getting back to me. I based the code in \Basenotes\Reviews\Reaction\Review::getEntityWith with this from the video.

Screenshot 2025-05-19 at 13.39.37.webp

I have now switched that out for 'User', and I'm no longer getting the error, but it's also not loading up the reactions, see screenshot (the heading loads, but not the Users):

Screenshot 2025-05-19 at 12.17.22.webp

Would it be an issue that the tutorial Is on XF2.2 and I'm on 2.3? Also, are the files for the Demo Scratch Pad plug-in available somewhere?

Thanks
 
I don't think the version difference should be too meaningful. If you open the page in a new tab, do you see any errors? Is anything logged to the server error log? Does adding and removing a reaction change anything (or at least update the counts correctly)? I don't think the files were published unfortunately.
 
Thanks for your time Jeremy

I don't think the version difference should be too meaningful. If you open the page in a new tab, do you see any errors?
No errors
Is anything logged to the server error log?
Nothing in the error logs

Does adding and removing a reaction change anything (or at least update the counts correctly)?
The counts are registered correctly - and the correct reaction is shown when it is chosen
However, on page load, the reaction (1) isn't rendered correctly, though though counts (2) are shown as correct

Screenshot 2025-05-19 at 21.02.10.webp
(this is just a screenshot of this page, to give you an idea of what bits I'm referring to)


I don't think the files were published unfortunately.
Oh that's a shame. Think I'll have to start again, and try and get the demo working before I try and adapt it for my needs.

If anyone else has managed to complete the demo, and would be wiling to share the code that would be really helpful :)
 
The code has been uploaded to the original HYS thread, whether or not it works correctly may be another story but hopefully it makes it easier to reference if nothing else. Looking over the code, it may be that you need to create a reaction_item_* template for your content type. I don't think this is covered in the videos, but you can see reaction_item_post for an example.
 
Back
Top Bottom