![]() |
Datamapper include_related group values to one object - 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 include_related group values to one object (/showthread.php?tid=57534) |
Datamapper include_related group values to one object - El Forum - 03-21-2013 [eluser]Sport_Billy[/eluser] I am having 3 tables Code: customers 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(); And trying to see the results like this: Code: foreach($customers as $c){ The returning object has the customer in 2 separate objects like this Code: John Smith desease1 While i want something like this: Code: John Smith Datamapper include_related group values to one object - El Forum - 03-21-2013 [eluser]WanWizard[/eluser] Datamapper doesn't have object instantiation for many-many relations. Datamapper include_related group values to one object - El Forum - 03-21-2013 [eluser]Sport_Billy[/eluser] Thanks for your reply WanWizard, it is nice to see you helping here. I figured it out too that it cannot be supported the way i did it with include_related. I ended up using subqueries and GROUP_CONCAT function, because it still does what i wanted. Here is the code i used based on the example above in case someone has similar problem: Code: $customer = new Customer(); So the results for the example will come from this output: Code: foreach($customers as $c){ And will produce something like this: Code: John Smith |