Welcome Guest, Not a member yet? Register   Sign In
dmz help
#1

[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.
#2

[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
#3

[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;




Theme © iAndrew 2016 - Forum software by © MyBB