mercredi 19 octobre 2016

Implementing many to many relation in mysql

I have two tables

1.Rectangle(rectId , xPos , yPos , height , width)

2.Scale(scaleId , someothercols...)

Now each column in the rectangle can have ' 0 to 1 ' scale associated with it.

i.e xPos can have a scale,yPos can have a scale and so on . So in general a single rectangle can have more than one scales.

Also a scale can be referenced by more than one rectangle .

What is the best way to implement this in sql

The way i thought of is having a junction table Rectangle_scale with rect_column attribute exg :

Rectangle_scale

| rectScaleId | rectId      | scaleId      | rect_col(string)|
|:----------- |------------:|:------------:|---------------- | 
| 1           |      1      |     2        |  Xpos           |
| 2           |      1      |     3        |  Ypos           | 
| 2           |      2      |     2        |  Height         | 

Is this the right way to do this? Also do I need the rectScaleId col ,or should I use rectId and scaleId as a composite primary key

Also,something to mentioned which is not directly related to the quesion ,i am using Laravel 5.2 framework with eloquent ,not necessarily required but the solution which adheres to the limitation of Laravel's eloquent would be nice



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire