[英]cakephp 3 model is not associated error
表格coding
id | level1 | level2 | title _____________________________________ 1 | 100 | 1 | numberOne 2 | 100 | 2 | NumberTwo 3 | 101 | 1 | Compay 4 | 101 | 2 | association
表Organizations
id | name | type | level ____________________________ 1 | intel | 3 | 1 2 | IBM | 4 | 2
示范Organizations
class organizationsTable extends table
{
public function initialize(array $config)
{
$this->table('organizations');
$this->primaryKey('id');
$this->belongsTo('yyyy', [
'foreignKey' => 'type',
'className' => 'coding'
],
'xxxx', [
'foreignKey' => 'level',
'className' => 'coding'
]);
}
}
控制者
$organization->find('all')->contain(['yyyy'])->contain(['xxxx'])->toList() ;
我寫這個但說錯誤: organizations is not associated with xxxx
在cakephp3中如何對同一個模型建立多重關系?
在cakephp2 中與同一模型的多個關系
但是在cakephp3中嘗試這樣
模型
$this->belongsTo('aliasName1', [
'foreignKey' => 'type',
'className' => 'coding'
]);
$this->belongsTo('aliasName2', [
'foreignKey' => 'level',
'className' => 'coding'
]);
控制者
$organization->find('all')->contain(['aliasName1'])->contain(['aliasName2']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.