PostsTable
belongsTo
AuthorsTable
用Google搜索了很多,找不到任何东西。必须即兴创作。
// in my controller action:
// set custom class for authors
$authorsTable->setEntityClass('App\Model\Entity\AuthorCustom');
// get authors
$results = $authorsTable->find('all');
那很好。
// in my controller action:
// set custom class for authors
$authorsTable->setEntityClass('App\Model\Entity\AuthorCustom');
// get products including categories
$results = $postsTable->find('all')->contain($authorsTable);
这不起作用,因为contain()
不接受表实例。
有人知道仅通过一次find()
通话即可设置不同实体的方法吗?
答案 0 :(得分:0)
它不起作用,因为contain()
接受一个array | string | null,并且您试图将其传递给Table
实例。将表名称传递给它,而不是用于水合作用:
// in my controller action:
// set custom class for authors
$authorsTable->setEntityClass('App\Model\Entity\AuthorCustom');
// get products including categories
$results = $postsTable->find('all')->contain($authorsTable->getTable());