At the moment I can only search fields from the main table.
Here is a copy of my model
<?php
class users_crud_model extends grocery_CRUD_Model {
// --------------------------------------------------------------------
/**
* Initialisation function (__construct)
*
* Initialise, get parent properties and retrieve any messages
*
* @access public
* @return void
*/
public function __construct(){
parent::__construct();
}
function get_list() {
if($this->table_name === null) {
return false;
}
$select = "{$this->table_name}.*";
// ADD YOUR SELECT FROM JOIN HERE
$_select = array(
'user_profiles.firstname',
'user_profiles.lastname',
'user_profiles.margin',
'user_profiles.created_by',
'user_profiles.rep_code',
);
$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);
// ADD YOUR JOIN HERE for example:
$this->db->join('user_profiles','user_profiles.user_id = users.id');
if ($this->profile_data['role'] != 'admin') {
$this->db->where('activated', 1);
}
else {
$this->db->order_by('activated', 'asc');
}
$results = $this->db->get($this->table_name)->result();
return $results;
}
}