1 year ago

Many to many relationship

Posted 1 year ago by kadridge

Hello People,

Quick question;

I have a system where you can create a module and associate components, so my relation is that a module has many components and a components belongs to many modules, but the thing is a module can have multiple of the same component so my pivot table will look like:

module_id component_id

and in my table I could have entries like:

| module_id | component_id |


| 1 | 1 |

| 1 | 2 |

| 1 | 1 |

I can't obviously make the combination of module_id and component_id a unique primary key, and so I will have to add a new id column as unique primary key.

Sounds like a silly question but I wanted to know if I should be aware of some configuration I should set in my Models to make this work with Eloquent or if anyone has a better approach ?

Thanks for your help !

Please sign in or create an account to participate in this conversation.