This bit me today so I figured it might be worth sharing.
The order in which you call methods in the query builder generally doesn't matter UNLESS you are using table aliases and table prefixes.
Here's a quick example, using a table prefix "ff_" :
PHP Code:
$this->db->select('C.contact_id');
$this->db->join('contact_meta as M', 'C.contact_id = M.contact_id', 'LEFT');
$this->db->from('contact as C');
Because the FROM is called after the JOIN, the alias is not tracked, so the SQL ends up as follows:
Code:
SELECT ff_C.contact_id
LEFT JOIN `ff_contact_meta` as `M`
ON `ff_C`.`contact_id` = `M`.`contact_id`
Note the erroneous ff_C prefix in the join - the alias 'C' was not tracked when the join SQL was created, so the table prefix was applied in the wrong place.
Placing the FROM call prior to the JOIN resolves this.
Might be worth either updating the docs to reflect this (if it's not considered a bug, that is).