Codeigniter ORM unable to ceate relation

96 views Asked by At

Trying to establish a simple multiple relation between two tables.

Unfortunately Codeigniter keeps saying:

"Unable to locate the model you have specified: eventtrigger".

Here comes the code:

class Task extends DataMapper
{
    public $has_one = array('employee',
                            'eventtrigger' => array('class' => 'employee'));

    […]
}

I know, this is very few information.

But I hope there is a known problem concerning this construct.

regards:maak.

1

There are 1 answers

0
froddd On

You need to also define the relation's other_field property, and you also need to define the reverse relation in the Employee model:

class Task extends DataMapper
{
    public $has_one = array(
        'owner' => array(
            'class' => 'employee',
            'other_field' => 'owned_task'
        ),
        'trigger' => array(
            'class' => 'employee',
            'other_field' => 'triggered_task'
        )
    );
}

And in the Employee model:

class Employee extends DataMapper {
    $has_many = array(
        'owned_task' => array(
            'class' => 'task',
            'other_field' => 'owner'
        ),
        'triggered_task' => array(
            'class' => 'post',
            'other_field' => 'trigger'
        )
    );
}

For more info on this: http://datamapper.wanwizard.eu/pages/advancedrelations.html

Unfortunately, as @bmorenate mentioned, DataMapper isn't actively supported anymore.