Hi all, may I ask one question about grocerycrud models?
My question is below:
I want to list some data that need to join some tables to retrive the data, so I created my models (named 'goods_models') and load it in the controller, something like this:
function show()
{
$crud = new grocery_CRUD();
$crud->set_model('goods_model');
$crud->set_theme('datatables');
$crud->set_table('goods');
$crud->columns('id', 'type_code', 'item_type_code', 'preview_url', 'file_url_android', 'file_url_ios', 'name', 'title', 'content', 'downloads', 'hot_value', 'time_beg', 'time_end');
$crud->add_fields('id', 'type_code', 'item_type_code', 'preview_url', 'file_url_android', 'file_url_ios', 'name', 'title', 'content', 'downloads', 'hot_value');
$crud->edit_fields('id', 'type_code', 'item_type_code', 'preview_url', 'file_url_android', 'file_url_ios', 'name', 'title', 'content', 'downloads', 'hot_value');
$crud->set_subject('goods');
$output = $crud->render();
$this->load->view('show.php',$output);
}
and my 'goods_model' :
function get_list() {
if($this->table_name === null) {
return false;
}
$select = "{$this->table_name}.*";
$_select = array(
'goods.id', 'goods.type_code', 'goods.item_type_code', 'goods.preview_url, goods.file_url_android, goods.file_url_ios, cooperation.name, good_text.title, good_text.content, good_shopping.downloads, good_shopping.hot_value, good_shopping.time_beg, good_shopping.time_end'
);
$select .= ','. implode(',', $_select);
if( ! empty($this->relation))
foreach ($this->relation as $relation) {
list($field_name , $related_table , $related_field_title) = $relation;
$unique_join_name = $this->_unique_join_name($field_name);
$unique_field_name = $this->_unique_field_name($field_name);
if (strstr($related_field_title,'{')) {
$select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name";
}
else {
$select .= ", $unique_join_name.$related_field_title as $unique_field_name";
}
if ($this->field_exists($related_field_title)) {
$select .= ", {$this->table_name}.$related_field_title as '{$this->table_name}.$related_field_title'";
}
}
$this->db->select($select, false);
$this->db->join('good_coop','good_coop.good_sn = goods.sn')
->join('cooperation','cooperation.sn = good_coop.coop_sn')
->join('good_shopping','good_shopping.good_sn = goods.sn')
->join('good_text','good_text.good_sn = goods.sn');
$results = $this->db->get($this->table_name)->result();
return $results;
}
For the list data, it's work very well and can show all of the data from 5 join table (good, good_coop, cooperation, good_shopping, good_text).
However, since in the controller, we only can set one table, and I set it into 'goods' ($crud->set_table('goods') ;), I always get this error result:
Error Number: 1054
Unknown column 'name' in 'field list'
INSERT INTO `goods` (`id`, `type_code`, `item_type_code`, `preview_url`, `file_url_android`, `file_url_ios`, `name`, `title`, `content`, `downloads`, `hot_value`) VALUES ('33', '2', '2', '33', '33', '33', '33', '33', '33', '33', '33')
'
Which means it just insert to 'goods' table instead of the specific 4 others table that I've joined in the 'goods_model'.
Any solution for this problem?
Thanks before!
Thank you~
