CodeIgniter Forums
Datamapper ORM 1.8.2 Need help with menu - 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 ORM 1.8.2 Need help with menu (/showthread.php?tid=59506)



Datamapper ORM 1.8.2 Need help with menu - El Forum - 10-13-2013

[eluser]Unknown[/eluser]
Hi everyone,

Categories
============
ID Name
-----------------
1 TV
-----------------
2 LED
-----------------
3 LCD
-----------------

Subcategories
============
id category_id subcategory_id
-----------------------------
1 1 2
-----------------------------
2 1 3

category_id is linked to ID of Categories and subcategory_id is linked to ID of Categories.

I've got all the relationships set and when I do something like the following:

Code:
foreach ( $categories as $cat )
{
    foreach ( $cat->subcategories->get() as $subcat )
    {
        echo $subcat->subcategory->get()->name . '<br/>';
    }
}

Output:

TV
TV

Even though the output should be more like this:

LED
LCD


I've gone completely code blind, I've been trying to figure this out for a few days now and it's driven me insane.

Thank you very much for any help.

Oh and if anymore info is required please let me know I'm more then happy to provide it.


Datamapper ORM 1.8.2 Need help with menu - El Forum - 10-14-2013

[eluser]WanWizard[/eluser]
Sounds like an error in defining your relations.