Table “App\Model\Table\UsersTable” is not associated with “id” in cakephp3
If you want help:
- Ask a question
- Show what you tried
- Show your relevant code
i’m getting the same error, can you help?
this is my users table:
class UsersTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
//$this->hasMany('documents');
$this->setTable('users');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
}
}
and here is the documents table i’m trying users to associate with:
class DocumentsTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->belongsTo('Users');
//$this->setForeignKey('admin_id');
$this->setTable('documents');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
}
}
this is the error i’m getting:
How does your Users table structure looks like? Do you have an id
field?
yes, I have ‘id’ in users table and ‘user_id’ in documents table.