Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ctyler's avatar

Can you use a pivot model in a Many to Many relationship?

I am working on a ticket application where non agents can be assigned a ticket and they are called auditors. The way this current works is when filling out a ticket you must select a category. When the category is selected the ticket submitter is then presented with tags that are assign to that category. Users are required to select at least one. Auditors are assigned to tickets by the tags that are chosen. On the back end you can assign one or more auditors to a tag. So now we have three tables:

category
Id	Name
tag
Id	Name
category_Tag
Id	category_id	Tag_id
auditor_tag
id	user_id	Tag_id

This has become slightly more complicated because a tag that is assigned to more than one category could now have different auditors.

So for instance currently: {Tag A} has {auditor A} assigned to it and {Tag A} is assign to {Category A} {Tag A} can also be assigned to {Category B}

This now needs to be changed to {Tag A} that is Assigned to {Category A} needs to have one or more Auditors assigned to it {Tag A} that is assigned to {Category B} may have one or more different Auditors assigned to it.

So now I need:

category_tag
Id	category_id	Tag_id
PIVOT
category_tag_users
Id	category_tag_id	users_id
users
Id		

I think this is possible but I am not sure if this would be the best way to approach this. I am not very familiar with pivot models but does this look like a situation where that would be used?

0 likes
2 replies
vincent15000's avatar

A many to many relationship needs necessarily a pivot table.

Does it need a model ? It depends on your needs.

Example : a user pays a ticket to go to a concert. You have the users table, the concerts table and the pivot table : tickets. Here the ticket has a real existence and you will perhaps need to display the list of the tickets. In this case the pivot table needs a model. Another reason is that the ticket can also have more attributes.

Other example : a user can like a post. You have the users table, the posts table and the pivot table : likes. Here there is really no need to have a model, a like will not have any more attribute and it has no existence.

ctyler's avatar

@vincent15000 Ok. so what if I need to create a many to many relationship between the ticket_users and another model?

Please or to participate in this conversation.