[eluser]Unknown[/eluser]
I have a function like this in my model (a modified version of bitauth by danmontgomery)
Code:
public function get_users($include_disabled = FALSE)
{
if( ! $include_disabled)
{
$this->db->where('users.enabled = 1', NULL, FALSE);
}
$this->db
->select('users.*, userdata.*, groups.id AS group_id, groups.name AS group_name, BIT_OR(groups.roles) AS roles, BIT_OR(users.user_roles) AS user_roles')
->from($this->_table['users'].' AS users')
->join($this->_table['data'].' AS userdata', 'userdata.user_id = users.id', 'left')
->join($this->_table['assoc'].' AS assoc', 'assoc.user_id = users.id', 'left')
->join($this->_table['groups'].' AS groups', 'groups.id = assoc.group_id', 'left')
->group_by('users.id');
$query = $this->db->get();
}
I
expected the sql that was output would be :
Code:
SELECT `users` . * , `userdata` . * , `groups`.`id` AS group_id, `groups`.`name` AS group_name, BIT_OR( groups.roles ) AS roles, BIT_OR( users.user_roles ) AS user_roles
FROM (
`1_users` AS users
)
LEFT JOIN `1_user_data` AS userdata ON `userdata`.`user_id` = `users`.`id`
LEFT JOIN `1_users_groups` AS assoc ON `assoc`.`user_id` = `users`.`id`
LEFT JOIN `1_groups` AS groups ON `groups`.`id` = `assoc`.`group_id`
WHERE users.email = '[email protected]'
AND users.enabled =1
But instead,
it returned me :
Code:
SELECT `users` . * , `userdata` . * , `groups`.`id` AS group_id, `groups`.`name` AS group_name, BIT_OR( groups.roles ) AS roles, BIT_OR( users.user_roles ) AS user_roles
FROM (
`1_users` AS users
)
LEFT JOIN `1_user_data` AS userdata ON `userdata`.`user_id` = `users`.`id`
LEFT JOIN `1_users_groups` AS assoc ON `assoc`.`user_id` = `users`.`id`
LEFT JOIN `1_groups` AS groups ON `groups`.`id` = `assoc`.`group_id`
WHERE 1_users.email = '[email protected]'
AND 1_users.enabled =1
The problem being, the AR method that I chained after checking a condition does not respect the table alias that I have set in the main query. Is this a bug? Or am I doing anything wrong?