public function index()
{
$title = 'Order list';
$orders = $this->Paginator->paginate($this->Clients_products->find('all', ['contain' => ['Clients', 'products']]));
$this->set(compact('title', 'orders'));
}
This is code my model :
<?php
// src/Model/Table/Clients_productsTable.php
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class Clients_productsTable extends Table
{
public function initialize(array $config)
{
// $this->belongsTo('Clients'); // I tried this is too
$this->belongsToMany('Clients');
$this->belongsToMany('Products');
}
}
?>
But I always get the error :
The clients association is not defined on Clients_products.
Check whether $this->Clients_products is of the class that you expect it to be. $this->ClientsProducts would be more standard, and the class called ClientsProductsTable.
<?php
// src/Model/Table/Clients_productsTable.php
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class ClientsProductsTable extends Table
{
public function initialize(array $config)
{
// $this->belongsTo('Clients');
$this->belongsToMany('Clients');
$this->belongsToMany('Products');
}
}
The result is the same
# The clients association is not defined on Clients_products.InvalidArgumentException
Table class names are plural, PascalCased and end in Table . UsersTable , ArticleCategoriesTable , and UserFavoritePagesTable are all examples of table class names matching the users , article_categories and user_favorite_pages tables respectively.
Entity class names are singular PascalCased and have no suffix. User , ArticleCategory , and UserFavoritePage are all examples of entity names matching the users , article_categories and user_favorite_pages tables respectively.