I think I have discovered a bug and am looking for a way to fix this.
I am using CI 3.0.1. The problem happens when I have a space in my search parameter for a like query. This causes `items.name` to NOT have a prefix in the where clause. (It should be `phppos_items`.`name`)
Is this considered a bug or is there a workaround?
ACTIVE RECORD CODE: (Notice search = 'test')
$search = 'test';
$this->db->select("items.*,categories.name as category");
$this->db->from('items');
$this->db->join('categories', 'categories.id = items.category_id','left');
$this->db->where('items.deleted',0);
$this->db->like('items.name', $search);
$this->db->limit($limit);
$by_name = $this->db->get();
echo $this->db->last_query();
QUERY RESULT:
SELECT `phppos_items`.*, `phppos_categories`.`name` as `category`
FROM `phppos_items`
LEFT JOIN `phppos_categories` ON `phppos_categories`.`id` = `phppos_items`.`category_id`
WHERE `phppos_items`.`deleted` =0 AND `phppos_items`.`name` LIKE '%test%' ESCAPE '!' LIMIT 100
ACTIVE RECORD CODE: (notice search is test 2)
$search = 'test 2';
$this->db->select("items.*,categories.name as category");
$this->db->from('items');
$this->db->join('categories', 'categories.id = items.category_id','left');
$this->db->where('items.deleted',0);
$this->db->like('items.name', $search);
$this->db->limit($limit);
$by_name = $this->db->get();
Query Result
SELECT `phppos_items`.*, `phppos_categories`.`name` as `category`
FROM `phppos_items`
LEFT JOIN `phppos_categories` ON `phppos_categories`.`id` = `phppos_items`.`category_id`
WHERE `phppos_items`.`deleted` =0 AND items.name LIKE '%test 2%' ESCAPE '!' LIMIT 100