1

i have 2 tables namely users and employers . I would like to match them together like tinder style, which means that when both the user and the employer liked each other , they will each receive a notification .

However i am not sure how would the relationship table will look like??

Right now what i have is in the Relationship Table ,

1.user_id

2.target_employer_id

3.employer_id

4.target_user_id

If i am not wrong , this is considered as a Many - Many relationship. So , is this table correct???

Manashvi Birla
  • 2,837
  • 3
  • 14
  • 28
EggRollMan
  • 583
  • 1
  • 8
  • 20

1 Answers1

1

As I understand your question, in your application, a user can like an employer, and an employer can like a user.

If this is right, it seems clear to me that there are two distinct (many to many) relationships (user => employer, employer => user), and that in your proposed table only two fields are filled at a time.

The best way to represent those relationships is to use two tables.

User to employer fields:

  1. user_id
  2. target_employer_id

Employer to user fields:

  1. employer_id
  2. target_user_id

Depending if you are using Laravel 4 or Laravel 5, you can use one of those two packages to generate the two pivot tables via a migration:

https://github.com/JeffreyWay/Laravel-4-Generators

https://github.com/laracasts/Laravel-5-Generators-Extended

AGR
  • 26
  • 4
  • Thanks alot for the reply. But how would i check if they are both liked each other? like they are a matched? – EggRollMan Jun 03 '15 at 10:10
  • It depends in which context you are looking for the information. – AGR Jun 03 '15 at 10:17
  • What if I want them to set a meeting date ? Does that mean I need another table called "Meetings" ? And if it is, the column would be something like user_id, employer_id and date ? – EggRollMan Jun 03 '15 at 10:23
  • 1
    It depends in which context you are looking for the information. If for example you are asking, in the point of view of a user, with which employer the relation is mutual, you can do something like the following query (not tested): `SELECT employer_id FROM UserEmployer UE JOIN EmployerUser EU ON UE.employer_id = EU.employer_id AND UE.user_id = EU.user_id WHERE UE.user_id = 123` And yes, for the meeting, it is definitely another kind of object that should be stored in a different table. – AGR Jun 03 '15 at 10:24
  • Okay. I think I roughly get what you are trying to say. Lemme try it out first . thanks again – EggRollMan Jun 03 '15 at 10:28