0
관련 데이터로 쿼리를 수행했습니다. 작동하고 모든 데이터를 표시합니다 (아래 명시).cakephp3 디버그에서 복잡한 검색 결과 표시
내 디버그 출력에 [] 대괄호 안에 많은 추가 필드가 포함되어 있으므로이를 어떻게 선택의 필수 데이터로만 제한하고 [] 대괄호에 추가 필드가 없습니까?
cakephp3에서 이와 같은 관련 데이터를 가져 오는 최적의 방법은 무엇입니까? 나는 cakephp2에 익숙해 져있다. 많은 테이블에서 찾을 수있는 코드는 cakephp3에 훨씬 적지 만 cakephp2 매개 변수를 선호한다. 찾기 및 조건에 대한 조인을 사용하는 데 익숙하지만, cakephp3에는 조인 코드가 필요하지 않습니다.
$query3 = $this->Bookmarks->find()
->contain(['Users'])
->select(['bookmarks.id','bookmarks.title','users.id'])
->where(['bookmarks.id' => 1]) ;
$query3->matching('Tags', function ($q) {
return $q
->select(['tags.id'])
->where(['Tags.title like' => '%tes%']);
});
foreach ($query3 as $row) {
debug($row);
}
//bookmarks model
public function initialize(array $config)
{
parent::initialize($config);
$this->table('bookmarks');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);
$this->belongsToMany('Tags', [
'foreignKey' => 'bookmark_id',
'targetForeignKey' => 'tag_id',
'joinTable' => 'bookmarks_tags'
]);
}
'bookmarks' => [
'id' => '1',
'title' => 'kmkl'
],
'users' => [
'id' => '1'
],
'tags' => [
'id' => '1'
],
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Bookmarks'
http://book.cakephp.org/3.0/en/orm/query-builder.html
toArray();'''를 시도한 다음 결과를 루프/디버깅하십시오. – Salines