Welcome Guest, Not a member yet? Register   Sign In
datamapper multi-tables

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. Smile

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,
concat(clients.first_name, " ", clients.last_name)', FALSE)
->join('sites', 'leads.site_id = sites.site_id', 'left')
->join('clients', 'sites.client_id = clients.client_id', 'left');
return $this->db->get()->result();

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 Smile

Theme © iAndrew 2016 - Forum software by © MyBB