How can I use this snippet of the Book (Associations - Linking Tables Together) :
class ArticlesTable extends Table
{
public function initialize(array $config): void
{
$this->hasMany(‘Comments’)
->setFinder(‘approved’);
$this->hasMany('UnapprovedComments', [
'className' => 'Comments'
])
->setFinder('unapproved')
->setProperty('unapproved_comments');
}
}
After adding a column ‘approved’ (type boolean) to the comments table I get:
Unknown finder method “approved” on App\Model\Table\CommentsTable.
Do they want 2 columns approved and unapproved?
CommentsTable:
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('comments');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER',
]);
$this->belongsTo('Articles', [
'foreignKey' => 'article_id',
'joinType' => 'INNER',
]);
}