Saturday, April 13, 2013

Proper Relations Question

I need to properly configure this model relationship and was looking for some insight.

 

Basically :

Company hasMany Employees

Company hasMany Contracts

 

I need to allow the administrator for that Company to assign a Contract to and Employee

So Employee hasMany Contracts but the Contract <-> Company, what is the best way to relate the Contract <-> Employee in the database with relations?

 

Build a separate table employees_contracts with id, contract_id, employer_id, employee_id?

But how to link employee to contract without having a employee_id in the contract table?

 

Ideally the Employee logs in and they see the set of Contracts assigned to them, without having to actually have employee_id in the Contract table since it really belongs to the Company.

 

Any tips would be great.

 

Thanks,

 

Dave

No comments: