Welcome Guest, Not a member yet? Register   Sign In
Possible Bug in Active Record when ordering by aliased field
#1

[eluser]Unknown[/eluser]
Working with Flexigrid in CI and think I may have uncovered a possible issue with Active Record in CI, specifically when dealing with order_by(). Trying to sort based on the columns in flexigrid.

First off, here's the code from my model:

Code:
//Select table name
        $table_name = "employee_types type, employees emp";
        
        //Build contents query
        $this->db->select('emp.uuid, emp.last_name, emp.first_name, emp.email, type.name as e_type', FALSE)->from($table_name, FALSE);
        $this->db->where('emp.employee_type_id', 'type.uuid' , FALSE);

        $this->CI->flexigrid->build_query();

        //Get contents
        $return['records'] = $this->db->get();
When I select the column for last_name, it works fine. In fact here's the query from my log:

Code:
SELECT emp.uuid, emp.last_name, emp.first_name, emp.email, type.name as e_type
FROM (employee_types type, employees emp)
WHERE emp.employee_type_id =type.uuid
ORDER BY last_name asc
LIMIT 15

However, if I click on the employee type column, I get the following error.

Code:
INFO  - 2009-07-09 17:39:37 --> Query: SELECT emp.uuid, emp.last_name, emp.first_name, emp.email, type.name as e_type
FROM (employee_types type, employees emp)
WHERE emp.employee_type_id =type.uuid
ORDER BY e_type asc
LIMIT 15
DEBUG - 2009-07-09 17:39:37 --> DB Transaction Failure
ERROR - 2009-07-09 17:39:37 --> Query error: Unknown column 'e_type' in 'order clause'

This query works fine when run in PHPMyAdmin. Only thing different in the two queries (from CI perspective is one sorts on last_name, one on employee_type.name (aliased to e_type).

I've also tried passing in the full name (employee_types.name), the field alias (e_type) as well as table alias/name (type.name). None of them work from CI.

Any ideas what is going on? More than willing to provide more code or information if needed.

Thanks in advance!
-DK




Theme © iAndrew 2016 - Forum software by © MyBB