0

I'm creating a plugin RubriquesManager in which there are the 2 associated Tables Rubriques and Blocs.

Rubriques hasmany Blocs

Blocs belongsTo Rubriques

When Rubriques and Blocs were not in the RubriquesManager all worked well but now there are, I have the following error inside BlocsTable::initialization() : Table class for alias Rubriques could not be found.

Here's my code :

// in plugin/RubriquesManager/Model/Table/BlocsTable.php
namespace RubriquesManager\Model\Table;

class BlocsTable extends AbstractBlocsTable
{
    public function initialize(array $config): void
        {
            parent::initialize($config);

            $this->belongsTo('RubriquesManager.Rubriques');

            $rubriques = $this->Rubriques->find(); // Trigger the error : "Table class for alias Rubriques could not be found."
            // [...]
        }

Anyone could help me to understand what's going on please ?

Oliv
  • 236
  • 3
  • 12
  • Referencing plugin models requires dot notation accordingly. The error indicates that there's something wrong with either the `RubriquesTable` class file location, file name, and/or class name. – ndm Jan 25 '23 at 18:04
  • @ndm Is it not possible to use `$this->Rubriques->find()` even if I do `$this->belongsTo('RubriquesManager.Rubriques')` just the line before ? I have to use `TableRegistry::getTableLocator()->get('RubriquesManager.Rubriques')->find()` which I found less friendly to read... – Oliv Jan 27 '23 at 10:31
  • It is very much possible,in fact I've just tried it, and it works fine. I would be very surprised if using the locator with the same name would work, and using associations wouldn't, unless there's something additional involved that affects it. Try it in a new plain model and see if it makes any difference. Also make sure that the error is really triggered from where you think it is being triggered, ie check the stacktrace. – ndm Jan 27 '23 at 14:38
  • @ndm it works after clearing all cache... Thanks :) – Oliv Jan 27 '23 at 16:18

0 Answers0