2017-12-21 37 views
1

나는 join 테이블에 추가 데이터가있는 bolongsToMany 연관을 구현하려고합니다. 조인 테이블은 외래 키 열이 나는 상황이 조인 테이블에 저장에 beeing 예상 추가 열 '컨텍스트'Cakephp 3 - _joinData가있는 belongsToMany

articlesController: 
$article = $this->Articles->patchEntity($article, $this->request->getData()); 
debug($article);die; 


and in a Plugin-Behavior: 
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) 
{ 
    $data['Categories.Categories'] = ['id' => '1', '_joinData' => ['context' => 'Tag']]; 
    debug($data); 
} 

을 가지고 있지만 그렇지 않습니다. debgger는 다음과 같이 말합니다 :

/plugins/Categories/src/Model/Behavior/CategorizeableBehavior.php (line 37) 
object(ArrayObject) { 
    name => 'dfa' 
    description => 'er' 
    Categories.Categories => [ 
     'id' => '1', 
     '_joinData' => [ 
      'context' => 'Tag' 
     ] 
    ] 
} 
/src/Controller/ArticlesController.php (line 56) 
object(App\Model\Entity\Article) { 

    'name' => 'dfa', 
    'description' => 'er', 
    '[new]' => true, 
    '[accessible]' => [ 
     'name' => true, 
     'description' => true, 
     'created' => true, 
     'modified' => true 
    ], 
    '[dirty]' => [ 
     'name' => true, 
     'description' => true 
    ], 
    '[original]' => [], 
    '[virtual]' => [], 
    '[errors]' => [], 
    '[invalid]' => [], 
    '[repository]' => 'Articles' 

} 

내 카테고리와 컨텍스트는 어디에 있습니까? 내 코드에 무슨 문제가 있습니까?

답변

1

조인 데이터를 첨부하려면 중첩 된 배열에 있어야합니다.

$data['Categories.Categories'] = [ 
     ['id' => '1', '_joinData' => ['context' => 'Tag']] 
]; 

원하는 경우 여러 레코드를 첨부 할 수 있도록 중첩 된 배열이어야합니다.