Filter somehow being added?

edited May 2014 in Modules
Hi there,

So I have a module "Contestants" which has the following filters:

public $filters = array('users.email', 'model_search', 'status');

Then I have my list_items like so:

function list_items($limit = NULL, $offset = NULL, $col = 'name', $order = 'asc', $just_count = FALSE)
{
$this->db->join("users", "contestants.user_id = users.id");
$this->db->select('contestants.id, contestants.user_id, CONCAT(users.first_name, " ", users.last_name) as name, users.email', FALSE);
$data = parent::list_items($limit, $offset, $col, $order, $just_count);
return $data;
}

Now this should be working as intended no? A search I would expect to search through email, model_search and status fields. However, searching gives me an mySQL error:

A Database Error Occurred
Error Number: 1054

Unknown column 'contestants.user_name' in 'where clause'

SELECT COUNT(*) AS `numrows` FROM (`contestants`) JOIN `users` ON `contestants`.`user_id` = `users`.`id` WHERE (LOWER(users.email) LIKE "%orla%" OR LOWER(contestants.model_search) LIKE "%orla%" OR LOWER(contestants.status) LIKE "%orla%" OR LOWER(contestants.user_name) LIKE "%orla%")


Where is -- LOWER(contestants.user_name) LIKE "%orla%" -- coming from? o.O

Comments

  • edited 2:55AM
    Do you have a field of "user_name"? If so, is it set as the "display_field"?

    LOWER(contestants.user_name) LIKE "%orla% is coming from parent::list_items method call which is referring to the Base_module_model::list_items() method which subsequently calls a protected _list_items_query method.
  • edited 2:55AM
    I do and it is, changing:

    $this->db->select('contestants.id, contestants.user_id, CONCAT(users.first_name, " ", users.last_name) as name, users.email', FALSE);

    to

    $this->db->select('contestants.id, contestants.user_id, CONCAT(users.first_name, " ", users.last_name) as name, users.email, user.username', FALSE);

    is necessary for that to function, however it doesn't change the query at all, how can I overwrite whats coming from the parent list?
  • edited May 2014
    I can fix the search by changing 'display_field' => 'user_name', to 'display_field' => 'users.user_name', however that just breaks display field. Any way around this?
  • edited 2:55AM
    On line 294 of the Base_module_model in the list_items method, you can uncomment the $this->debug_query(); line to see what the actual query is. The display_field value automatically gets included in the filters list. If you don't want that, you could try unsetting it in your list_items method:
    unset($this->filters['user_name']
Sign In or Register to comment.