You cannot do this as field named like `a.id` doesn't exist. We do not have dots in our tables!

The original code works, but if we wanted to be really sure that all was escaped I would use:

    $by = $this->db->quoteName($alias) . '.' . $this->db->quoteName($by);

Never escape dot!