How to perform a join with CodeIgniter's Active Record class on a multicolumn key?

Posted by Scott Southworth on Stack Overflow See other posts from Stack Overflow or by Scott Southworth
Published on 2010-02-23T20:16:28Z Indexed on 2010/06/18 7:03 UTC
Read the original article Hit count: 221

I've been able to make this code work using CodeIgniter's db->query as follows:

$sql =
 'SELECT mapping_code,zone_name,installation_name 
  FROM installations,appearances,zones 
  WHERE 
  installations.installation_id = zones.installation_fk_id 
  AND appearances.installation_fk_id =  installations.installation_id 
  AND appearances.zone_fk_id = zones.zone_id 
  AND
  appearances.barcode = ?
 ';

return $this->db->query($sql,array($barcode));

The 'appearances' table throws a 'not unique table' error if I try this using the Active Record class.

I need to join appearances on both the zone and installations tables.

How can I do this?

© Stack Overflow or respective owner

Related posts about activerecord

Related posts about codeigniter