Welcome Guest, Not a member yet? Register   Sign In
Datamapper include_related group values to one object
#1

[eluser]Sport_Billy[/eluser]
I am having 3 tables

Code:
customers
   id  
   firstname
   lastname
deseases
   id
   desease_name
customers_deseases
   id
   customer_id
   desease_id

And i want to get the deseases of each customer.
For example let's say that customer John Smith has desease1 and desease2.
When using this code:

Code:
$customer = new Customer();
$customer->include_related('desease', array('desease_name'), true, true);
$customers = $customer->get();

And trying to see the results like this:

Code:
foreach($customers as $c){
                echo $c->firstname . $c->lastname;
                echo "<br/>";
                foreach($c->desease as $cd)
                {
                    echo $cd->desease_name;  
                    echo "<br/>";
                }
        }

The returning object has the customer in 2 separate objects like this
Code:
John Smith desease1
John Smith desease2

While i want something like this:
Code:
John Smith
desease1
desease2


Messages In This Thread
Datamapper include_related group values to one object - by El Forum - 03-21-2013, 06:52 AM
Datamapper include_related group values to one object - by El Forum - 03-21-2013, 09:55 AM
Datamapper include_related group values to one object - by El Forum - 03-21-2013, 10:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB