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

Add support for composite primary keys #665

Open
1 task
stoutput opened this issue May 13, 2022 · 1 comment
Open
1 task

Add support for composite primary keys #665

stoutput opened this issue May 13, 2022 · 1 comment
Labels
feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before

Comments

@stoutput
Copy link
Contributor

stoutput commented May 13, 2022

Describe the feature as you'd like to see it
There should be a way to specify composite primary keys on a model, either as a tuple or list:

class User(Model):
    __primary_key__ = ['user_id', 'email']
    # or,
    __primary_key__ = ('user_id', 'email')

What do we currently have to do now?
Masonite currently only supports single primary keys:

class User(Model):
    __primary_key__ = 'user_id'
  • Is this a breaking change?
@stoutput stoutput added the enhancement A feature that exists, works as intended but needs to be improved label May 13, 2022
@josephmancuso
Copy link
Member

josephmancuso commented May 16, 2022

Will need to modify some behavior in Masonite ORM to be able to support this.

Find

The find method will need to check if the record_id that is passed is a list AND if the primary keys are a list. If so then it should perform 2 where clauses (where key1 is value1 and key2 is value2)

Update

On the query builder there is an update method. Right now it is just checking the model primary key. We will need to refactor the code to the model where we pass the query builder into the model and leave the model responsible for setting the where clause. This will clean the code up a bit.

Save

The save method calls either update or create. The create method should be fine and the update method should be fine after the above section is changed.

Delete

The delete method is doing a similar where statement as the update method. This will need the same refactoring to move the where clause into the model class

After the above changes are done then the library will be able to do composite primary keys

@josephmancuso josephmancuso added the medium These issues are geared for people who have contributed to the project before label May 16, 2022
@josephmancuso josephmancuso added feature request A feature that does not yet exist but will be a good addition to the library and removed enhancement A feature that exists, works as intended but needs to be improved labels Jun 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before
Projects
None yet
Development

No branches or pull requests

2 participants