I need to use joins to bring some data, but when I perform the steps on user_join found in this topic /topic/264-join-tables/, but the mysql log indicates the following:
681 Query SHOW TABLES FROM `rc_web_funcionarios` 681 Query SHOW COLUMNS FROM `producto` 681 Query DESCRIBE `producto` 681 Query DESCRIBE `clasificacion` 681 Query SHOW COLUMNS FROM `producto` 681 Query SELECT producto.*, je2b7bb94.nombre as se2b7bb94, producto.nombre as 'producto.nombre' FROM (`producto`) LEFT JOIN `clasificacion` as je2b7bb94 ON `je2b7bb94`.`id` = `producto`.`clasificacion_id` LEFT JOIN `producto_sucursal` ON `producto`.`codigo` = `producto_sucursal`.`producto_codigo` LEFT JOIN `sucursal` ON `sucursal`.`id` = `producto_sucursal`.`sucursal_id` LEFT JOIN `fantasia` ON `fantasia`.`id` = `sucursal`.`zona_id` WHERE `sucursal`.`zona_id` = '2' GROUP BY `producto_sucursal`.`producto_codigo` LIMIT 25 681 Query SHOW COLUMNS FROM `producto` 681 Query DESCRIBE `producto` 681 Query DESCRIBE `clasificacion` 681 Query SELECT * FROM (`producto`) LEFT JOIN `clasificacion` as je2b7bb94 ON `je2b7bb94`.`id` = `producto`.`clasificacion_id` WHERE `sucursal`.`zona_id` = '2' 681 Query ROLLBACK 681 Query SET AUTOCOMMIT=1
my controller function is:
function productos() { $id = $this->uri->segment(3); if ($id) { $crud = new grocery_CRUD(); $crud->set_model('productos_join'); $crud->set_table('producto'); $crud->set_subject('Productos'); // $crud->set_relation_n_n('Total', 'producto_sucursal', 'sucursal', 'producto_codigo', 'sucursal_id', 'nombre', 'id'); $crud->unset_columns('id'); $crud->columns('nombre', 'codigo', 'total'); $crud->where('sucursal.zona_id', $id); $crud->unset_operations(); $crud->callback_column('Total', array($this, 'total')); $crud->set_relation('clasificacion_id', 'clasificacion', 'nombre'); $output = $crud->render(); $this->return["id"] = $id; $this->return["crudData"] = $output; $this->load->view('details', $this->return); } else { redirect('main/empresas'); } }
and my custom model is:
class productos_join extends grocery_CRUD_Model { function get_list() { if ($this->table_name === null) return false; $select = "{$this->table_name}.*"; 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('producto_sucursal', 'producto.codigo = producto_sucursal.producto_codigo', 'left'); $this->db->join('sucursal', 'sucursal.id = producto_sucursal.sucursal_id', 'left'); $this->db->join('fantasia', 'fantasia.id = sucursal.zona_id', 'left'); $this->db->group_by('producto_sucursal.producto_codigo', 'left'); $results = $this->db->get($this->table_name)->result(); return $results; } }
wich means the custom model doesnt work and is overwritten by $crud->set_table('producto');