CodeIgniter Forums
dmz help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: dmz help (/showthread.php?tid=28051)



dmz help - El Forum - 02-28-2010

[eluser]richzilla[/eluser]
Hi all, im having a bit of trouble getting my head around the DMZ advanced relationships. Basically im looking for someone to fit my scenario to the advanced relationships and see if that helps me get my head round it. basically i have two models a user and an issue. The relationship between user and issue is simple:
Code:
1 user can have many issues

however 'issue' is a bit more complicated. Issue has the fields 'raised_by', 'assigned_to','closed_by', all of which represent a row in the user table. How would i code the relationships to demonstrate this?

Any help would be greatly appreciated.


dmz help - El Forum - 02-28-2010

[eluser]naren_nag[/eluser]
Code:
class Issue extends DataMapper {

    $has_one = array(

        'created_by' => array(
            'class' => 'user',
            'other_field' => 'created_issues'
        ),


        'raised_by' => array(
            'class' => 'user',
            'other_field' => 'raised_issues'
        ),

        'assigned_to' => array(
            'class' => 'user',
            'other_field' => 'assigned_issues'
        ),

        'closed_by' => array(
            'class' => 'user',
            'other_field' => 'closed_issues'
        )
    );
}

And the User model

Code:
class User extends DataMapper {

    $has_many = array(

        'created_issues' => array(
            'class' => 'issue',
            'other_field' => 'created_by'
        ),

        'raised_issues' => array(
            'class' => 'issue',
            'other_field' => 'raised_by'
        ),

        'assigned_issues' => array(
            'class' => 'issue',
            'other_field' => 'assigned_to'
        ),

        'closed_issues' => array(
            'class' => 'issue',
            'other_field' => 'closed_by'
        )
    );
}

For more go here: http://overzealous.com/dmz/pages/advancedrelations.html


dmz help - El Forum - 05-04-2010

[eluser]Wazzu[/eluser]
Thanks, naren_nag
I too have a question: how do you populate it now?
This way is right?

Code:
$i = new Issue();
$i->created_by->get();
echo "Issue " . $i->id . " created by " . $i->created_by->name;