how to define bidirectional relationship in the same model

I am not able to add the bidirectional relationship in the same model:

$this->belongsTo('userid', 'Frontend\Models\Users', 'id', array(
    'alias' => 'user'
));

$this->addHasMany("Tutor\Models\Organization\Organization","userid",",Frontend\Models\Users","id" , array(
    'alias' => 'organization',
    'foreignKey' => array(
    'message' => 'User cannot be deleted because he/she has activity in the system'
)));


1.6k
edited Sep '14

My requirement is modular structure, I have defined a module and don't want to edit that module models and I need to add only from current module, I saw a abstract addHasMany but I do not know how to use it, I'm waiting for a reply

I added this line in initialize method

$this->addHasMany("Tutor\Models\Organization\Organization","userid",",Frontend\Models\Users","id" , array( 'alias' => 'organization', 'foreignKey' => array( 'message' => 'User cannot be deleted because he/she has activity in the system' )));

but getting error method not defined



19.6k

Ah, if is using models I can't help you.

edited Sep '14

When you say

but getting error method not defined

I'm assuming you're using the theoretically generater getter method?

Have you tried using

$model->getRelated('Namespace\Class');

?