Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for Pivot Tables #11

Open
etenzy opened this issue Mar 3, 2015 · 4 comments
Open

Improvements for Pivot Tables #11

etenzy opened this issue Mar 3, 2015 · 4 comments

Comments

@etenzy
Copy link

etenzy commented Mar 3, 2015

In my opinion a Pivot requires the $table->timestamps(); fields to support the ->withTimestamps(); function.
Also i would prefer an id field as primary key (First normal form).

Additionally a combined index between the relational id's would be a benefit for performance.

Correct me if I'm wrong

@laracasts
Copy link
Collaborator

Whatever is most common, I'm fine with.

@Mythos
Copy link

Mythos commented Mar 6, 2015

IMHO a primary key out of FK1 and FK2 would be best.
Like users_groups: PRIMARY(user_id, group_id)
At the moment you can add the same entry multiple times which does not make sense to me.

@etenzy
Copy link
Author

etenzy commented Mar 11, 2015

Thanks to @vinkla for commiting.
Currently i don't have the ability for pushing code up to github...

I've testet different cases:

PRIMARY(user_id, group_id) will end up with:
'Illuminate\Database\QueryException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'xxx-xxx' for key 'PRIMARY

UNIQUE(user_id, group_id) results similar...

Without checking the relation before inserting you will have two options:

  1. Use an incremented id field as primary key & no UNIQUE(user_id, group_id) key and get along with duplicates
  2. try/catch every save/attach on every many to many relation...

so...
The most open way is adding an incremented id field as primary key as default.

If you want to avoid duplicates just add an UNIQUE key and try/catch everything

@tabacitu
Copy link
Contributor

tabacitu commented Mar 8, 2020

@etenzy are you still using the package? If so, let me know what you think we should do about this, today, in 2020. I'm working on v2 #170 and would love to put this issue to rest. The package is finally getting the attention it deserves, no better time to have this if you still want it 😄

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants