How to define this relationship

I have 2 entities, company and school, I am about to add tags for them. So I added a relation model of ItemTags, it has itemid, itemtype (this is either company or school),

I wondering how do I add relationship for itemTags? if there is only one entity, I could just go in itemTags,

public function initialize()
    {
        $this->belongsTo('school_id', 'Models\School', 'id');
        $this->belongsTo('tags_id', 'Models\Tags', 'id');
    }

but where do I fit in if I have itemid and itemtype?

Hi, Iam not sure what you wont. Please, can you copy-paste all 3 models?



5.8k
edited May '15

Thanks , It is ok, I have changed my database design.

Basically, I was thinking to have 2 entitie tables of company and school, both of them have relations to tags. I want to store the relationship in one table, which is items_tags, and use a field 'type' to tell if it is related to company or school.

What I changed was to have 2 different relation tables, companytags and schooltags

Hi, Iam not sure what you wont. Please, can you copy-paste all 3 models?