cakephp 3模型没有关联错误
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
Table 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 中 Multiple relations to the same model
但在 cakephp3 中尝试这样
型号
$this->belongsTo('aliasName1', [
'foreignKey' => 'type',
'className' => 'coding'
]);
$this->belongsTo('aliasName2', [
'foreignKey' => 'level',
'className' => 'coding'
]);
控制器
$organization->find('all')->contain(['aliasName1'])->contain(['aliasName2']);
标签coding
id | level1 | level2 | title _____________________________________ 1 | 100 | 1 | numberOne 2 | 100 | 2 | NumberTwo 3 | 101 | 1 | Compay 4 | 101 | 2 | association
Table 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 中 Multiple relations to the same model
但在 cakephp3 中尝试这样
型号
$this->belongsTo('aliasName1', [
'foreignKey' => 'type',
'className' => 'coding'
]);
$this->belongsTo('aliasName2', [
'foreignKey' => 'level',
'className' => 'coding'
]);
控制器
$organization->find('all')->contain(['aliasName1'])->contain(['aliasName2']);