I have two tables: productfilters and productfiltervalues.
In the first table I have records like, Books, Electronics, Apparels etc.
In the second table, there are records relevant to the records in first table i.e., when we edit Books, we can add values dynamically which are referred by the ‘id’ of ‘Books’, like ‘Fiction’, ‘History’, ‘Poetry’ etc. Likewise, we have different data for ‘Electronics’ and ‘Apparels’ too.
Now, when i edit both tables at a time and save them on one click, the first table records are saved as i wish but the second table records are duplicated with the original values unchanged.
For this functionality, I have overwritten the admin controller method ‘create_or_save()’ and it makes trouble. I have given the code below.
Any help is much appreciated. Thanks.
if ($this->model->save($this->params['data'])) {
$this->load_model('ProductFilterValue');
if(isset($this->params['data'][$this->model->name]['product_filter_value']) && !empty($this->params['data'][$this->model->name]['product_filter_value'])){
foreach($this->params['data'][$this->model->name]['product_filter_value'] as $productfiltervalue){
$this->ProductFilterValue->save($productfiltervalue);
}
}
$this->flash('notice', 'Successfully saved!');
$url = MvcRouter::admin_url(array('controller' => $this->name, 'action' => $this->_redirect_action, 'id' => $id));
$this->redirect($url);
}
I am using wordpress 4.1 with WP MVC.
I found the answer. The ID was not bound and it was the one for the cause of the trouble. So, I modified the foreach statement like this:
Earlier the ID count was 2 and now the ID is bound with original parent record and it saved properly.
Thanks all.