我有联系,但是我没有得到正确的结果。
这是我的ArticlesTable:
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('Articles');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->hasMany('Articlesb', [
'foreignKey' => 'id'
]);
}
我的ArticlesbTable:
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('Articlesb');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->belongsTo('Articles', [
'foreignKey' => 'id',
]);
}
使用此查询效果很好:
$query = $this->Articles->find('all')
->autoFields(false)
->contain('Articlesb')
->select(['someField']);
但是当我使用groupBy时:
$query = $this->Articles->find('all')
->autoFields(false)
->contain('Articlesb')
->select(['someField'])
->group(['someField]);
我得到了这个结果:
"data": [
{
"id": 1,
"Articlesb": []
},
Articlesb中应包含所有字段。为什么在使用groupBy时无法获取字段?有人可以帮助我吗?