datamapper multi-tables - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: datamapper multi-tables (/showthread.php?tid=48911) |
datamapper multi-tables - El Forum - 02-01-2012 [eluser]Unknown[/eluser] Hello, I'm new to datamapper and I'm still a newbie, and I'm having a problem finding out how will I fetch data from the database that has 3 tables. my tables are: clients, sites, leads relationships are: clients has many sites sites has one client sites has many leads leads has one site what I want to know is how will I get all the leads that belongs to a client, because I cannot relate the leads table to clients table. clients and sites are related by client_id leads and sites are related by site_id I can determine that a lead belongs to client if that lead belongs to a site that owns by a client. If i would do it using active record I have something like this: I have 2 left joins $this->db->select('leads.leads_id, concat(leads.first_name, " ", leads.last_name), DATE_FORMAT(leads.registered_datetime, "%M %d, %Y"), leads.email, sites.domain_name, concat(clients.first_name, " ", clients.last_name)', FALSE) ->from('leads') ->join('sites', 'leads.site_id = sites.site_id', 'left') ->join('clients', 'sites.client_id = clients.client_id', 'left'); return $this->db->get()->result(); datamapper multi-tables - El Forum - 02-01-2012 [eluser]Unknown[/eluser] I'm waiting for a reply from datamapper orm experts. because I was planning on using datamapper for projects if I will be able to understand how it works with these kinds of relationships |