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

Chron's avatar
Level 6

Is it okay to have three foreign keys in a pivot table?

I have a many to many relationship to toys, models and children. When I give the child's toy, I want to know first if the child already owns that kind of toy with the same model. So my validation would be

($child->pivot->toy_id == $this->toy && $child->pivot->model_id == $this->model)

But I don't know if its okay to have three foreign keys in a pivot table?

0 likes
2 replies
Tray2's avatar

I would go with two pivots one for model_toy and one for child_toy.

Since there can be toys that no child yet owns.

Chron's avatar
Level 6

But how would you check it if the child has the same toy with the same model? Toy has many model and vice versa.

Please or to participate in this conversation.