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

Including support for composite primary keys #102

Open
pedrofmj opened this issue Oct 23, 2020 · 4 comments
Open

Including support for composite primary keys #102

pedrofmj opened this issue Oct 23, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@pedrofmj
Copy link
Contributor

Hello,

I currently use compoships in conjunction with a Trait made by myself that enables Composite Primary Keys.
Would you guys think it would be useful and meaningful including such trait into Compoships?
Since we are talking about composite foreign keys in compoships, it onlly makes sense if we also we have support for composite primary keys.
If it makes sense, I could do some code for it.
What do you think?

@pedrofmj pedrofmj changed the title Including support for primary composite keys Including support for composite primary keys Oct 23, 2020
@topclaudy
Copy link
Owner

As stated in the documentation:

There are situations where you'll need to match many columns in the definition of a relationship even when your models' tables have a single primary key.

So, Compoships allows us to define relationships with multiple keys, but those keys can be any set of columns, not just primary keys.

@topclaudy topclaudy added the enhancement New feature or request label Oct 23, 2020
@pedrofmj
Copy link
Contributor Author

Hi @topclaudy , I fully understand your point.
But what I mean is that if we are adding support to composite foreign keys with compoships, it also makes sense to add support for composite primary keys in the same package, so that one that wants to use compoships also can set composite primary keys, that is not natively supported by Eloquent/Laravel.
I have a class for this, and I could add it to compoships.

@sinnbeck
Copy link

@pedrofmj Could you perhaps post the class? I would like to give it a try

@pedrofmj
Copy link
Contributor Author

pedrofmj commented Jan 19, 2021

@sinnbeck , it's a trait, called HasCompositePrimaryKey. You need to use that trait in your model. It's also important to correctly set the primaryKey in the model, (ex.: protected $primaryKey = ['key1', 'key2', ...]).

Here's the gist for the code:

https://gist.github.com/pedrofmj/614061eff182626b7f2056073edc600e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants