cakephp 3 + can't update database record when using translate behavior and 'contain' -


i using cakephp 3 , trying pretty basic stuff. have 2 tables, articles , tags. articles belongs tags, , made table tags translatable attaching translate behavior.

class articlestable extends table {             public function initialize(array $config) {         $this->addassociations([             'belongsto' => ['tags']         ]);     }          }  class tagstable extends table {             public function initialize(array $config) {         $this->addassociations([                         'hasmany' => ['articles'],                     ]);         $this->addbehavior('translate', ['fields' => ['name']]);     }        } 

in article controller have edit function:

class articlescontroller extends appcontroller {      public function edit($id = null) {         $article = $this->articles->get($id);         if ($this->request->is(['post', 'put'])) {                     $this->articles->patchentity($article, $this->request->data);             if ($this->articles->save($article)) {                 $this->flash->success(__('your article has been updated.'));                 return $this->redirect(['action' => 'edit',$id]);             }             $this->flash->error(__('unable update article.'));         }         $this->request->data = $article;          $tags = $this->articles->tags->find('list');         $this->set('tags', $tags);     } }  

in appcontroller setting locale language , @ point works fine, in edit.ctp file tags names in local language , updating working should.

but, when replaced following line in edit function in articlescontroller:

$article = $this->articles->get($id); 

with line:

$article = $this->articles->get($id, ['contain' =>  ['tags']]); 

i can no longer update article's tag.

if change body , tag in edit form, new body saved database. no error occurred, tag_id not changing.

if remove translate behavior tags table, tags not shown in local language, can updated again.

i stuck, have no idea in direction search, why can not use translate behavior , 'contain' @ same time?

any appreciated.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -