How to setup a many-to-many relationship?

I have a many-to-many relationship between Worker Group and Location, where one Worker Group can be at various Locations, though I do not want to create a belongs-to with the Location, since that would tie the Worker Group to one Location.

In a setup workflow I would like to create one Worker Group and assign it to many Locations, though I would also like to assign many other Worker Groups to various Locations.

Not all Worker Groups will be at all Locations.

How is this possible?

@gjeremenko you will need to implement this by means of an associative/join table. This Wikipedia entry explains it better than I could:

Practically you would need to add a new table (associate/join) which implements the many to many. This table, let us call it worker_assignment would represent a worker’s assignment to a location (worker --< worker_assignment >-- location):

  • worker has many worker_assignments
  • location has many worker_assignments
  • worker_assignment belongs to worker and belongs to location.

I hope this makes sense.


Makes perfect sense.