Struggling With The Database Design

Im making a website about job market, while developing I see many problems so I look back to the design to figure it out.

1- First is about something basic like employment. My scenario is this is employment management of many companies and users. User could have many skills, they can work as individual or as group. Company has many skills which are the requirements for the user. So it should be like that: companies add their skill requirements then it will list all available users or groups for each skill. Company then choose one ( hire the user or the group) then it will be put into the slot on the grid view that displays in the administrator management. There are 2 others tables WORKLOG and PAYLOG to manage the status of user and company. WORKLOG has attribute status with values: WORKING, NOT WORKING. PAYLOG has attribute status with values: PAID, NOT PAID. Therefore, when click on the slot, it must show out that which company and user on this slot, user still working or not, company pay for them or not. Other requirement is when click on any users, it must show all the slot they involving, what company they are working for, what their status of working. Same as company. Here is the list of table:


User:

- id

- skill_id

-group_id

Group:

- id

-skil_id

Skill:

- id

-group_id

-user_id

-company_id

Company:

-id

Worklog:

-id

-user_id

-group_id

-slot_id

-status

Paylog:

-id

-company_id

-slot_id

-status

Slot:

-id

-worklog_id

-paylog_id

-girdview_id

NOTE: there are 3 tables that not be counted in here: UserSkill, CompanySkill, UserGroup. They used to link between these table to create Many::Many relationship.




Please check if that design could work or not for this scenario. And building the relationship code for them.

Here is one of the example:( im using MANY:MANY relationship helper extenstion already)

User:




		return array(

			'fk_group_user' => array(self::MANY:MANY, 'Group', UserGroup'user_id, group_id'),

			'fk_skill_user' => array(self::MANY:MANY, 'Group', UserSkill'skill_id,user_id'),

			'fk_worklog_user' => array(self::HAS_MANY, 'Worklog', 'user_id'),

		);

Company:




		return array(

			'fk_skill_company' => array(self::MANY:MANY, 'Skill', CompanySkill'skill_id,company_id'),

			'fk_paylog_company' => array(self::HAS_MANY, 'paylog', 'company_id'),

		);

Worklog:




		return array(

			'fk_paylog_company' => array(self::BELONG_TO, 'Company', 'company_id'),

                        'fk_paylog_slot' => array(self::BELONG_TO, 'Slot', 'slot_id'),

		);

Slot:




		return array(

			'fk_paylog_slot' => array(self::HAS_MANY, 'Paylog', 'slot_id'),

                        'fk_work_slot' => array(self::HAS_MANY, 'Worklog', 'slot_id'),

		);

So when I select user by id with default method from CRUD generator: $model->loadmodel(). The $model able to wrap worklog and slot but not further. So far I have:


User:

$model->worklog: return array of worklog model objects

$model->group:return array of group model objects

$model->skill:return array of skill model objects

$model->company: none-properties object 

$model->slot : none-properties object 



It happened same as company, I could not wrap the users when perform findAll() by the relationship I created. The relationship is : user->worklog->slot<-paylog<-company. How I can know view all the companies that hire my selected user? Please help point out the mistake in my code and my design. Thanks alot :)

I think you have some problem with your db structure:




User:

- id

- skill_id

-group_id



For User, i think you could have more skill for user or not?




Group:

- id

-skil_id



As for User, also for Group i think you could have more skill for group;




Skill:

- id

-group_id

-user_id

-company_id



Skill should be indipendent for group and user; Could be dependent correctly for company;




Company:

-id



Ok;

Then i don’t understand how you have relationed worklog, paylog and slot;




Worklog:

-id

-user_id

-group_id

-slot_id

-status

Paylog:

-id

-company_id

-slot_id

-status

Slot:

-id

-worklog_id

-paylog_id

-girdview_id



I will clarify my scenario now. For example we have 2 companies :c1 and c2. C1 company looking for someone or some groups has skill: s1,s2. C2 need :s2,s3.




C1: - s1

    - s2

C2: -s2

    -s3



User u1 has 3 skills : s1, s2, s3 and form group g1 with u2 for skill s1, g2 with u2,u3 for s2

User u2 has 2 skills : s1, s2 and form group g1 with u1 for s1, form g2 with u1,u3 for s2

User u3 has 2 skill: s2, s3 and form g2 with u1,u2 for s2

So when those companies looking for employer, it will show like:




C1: -s1 ------> u1, u2, g1

    -s2 ------> u1, u2, g2

C2: -s2 ------> u1, u2, g2

    -s3 ------> u3



Then when they choose someone it will be put into a slot:




C1: --->[s1][u1] ---->slot1

   ---->[s2][g1]----->slot2

C2: ---->[s2][u2]---->slot3

    ---->[s3][u3]---->slot4



When we select slot 1 or query them. The result should be like that:


SLOT 1:

Name ---- Company ---- Skill ---- Empoyee(user/group)

Slot 1 ---- c1    ----   s1   ----  u1

And when we select company c1,it must show:


Company C1:

Skill-----Employee ----- Status

 s1 -----  u1      -----  Paid

 s2 -----  g1      -----  Not Paid



Same with user:


User 1:

Skill----- Group ---- Employer ----- Status

 s1 --  individual --  c1      ----  Working

 s2 -----  g1      --  c1      ----  Not Working   



For group:

Skill-----Employer ----- Status

s1 ----- c1 ----- Not Working

The worklog and paylog to store the status of user and company.

The relationship:




User -MANY::MANY- Group

User-MANY::MANY-Skill

Group--MANY::MANY-Skill

Company--MANY::MANY-Skill

User-ONE::MANY-Worklog

Group-ONE::MANY-Worklog

Company-ONE::MANY-Paylog

Paylog-ONE::ONE--Slot---ONE::ONE--Worklog

So i’ll make:




User:

- id






Skill:

- id






Group:

- id






UserSkill:

- user_id

- skill_id






UserGroup:

- user_id

- group_id






GroupSkills:

- group_id

- skill_id






Company:

-id






CompanySkillsNeeded:

- company_id

- skill_id






Slot:

- company_id

- group_id

- user_id

- skill_id



Thank you for correct my mistake.But it doesnt have something to count the status of user and company. Because I would like to know who still working or not, who get paid or not. And about the output above, what query would I have to call to get these results? By using loadAll() for user I have only:

User:

$model->worklog: return array of worklog model objects

$model->group:return array of group model objects

$model->skill:return array of skill model objects

$model->company: none-properties object

$model->slot : none-properties object

I need attribute of company and slot to display like that:

User 1:

Skill----- Group ---- Employer ----- Status

s1 – individual – c1 ---- Working

s2 ----- g1 – c1 ---- Not Working

In your relations’ model:




	public function relations()

	{

		return array(

            'skill'=>array(self::HAS_MANY, 'Skills', 'user_id'),

            'skillCount'=>array(self::STAT,'Skills','user_id'),

		);

	}



So on for others relations.

Run perfectly, thank in advance :)