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

feat: Extract Foreign Key from Payload #57

Merged
merged 11 commits into from
Mar 18, 2024

Conversation

cjmellor
Copy link
Owner

This PR aims to clean up some ways that the package handles things.

  1. Until now, if you created a Model that would be approved, e.g.
Comment::create(['body' => 'Hi']);

There would be a constraint violation when trying to approve the Model if it had a foreign key, i.e. a Comment model would normally have a relationship to a User model. Now, as long as the user adds the foreign key, everything should be okay, e.g.

Comment::create(['body' => 'Hi', 'user_id' => auth()->id()]);

If you were to add a comment via a relationship, e.g.

$user->comment()->create(['body' => 'Hi']);

there will be no difference, as this will always send the foreign key along with it.

  1. When creating a new Model (to be approved), and it had a relationship (like a user_id) then that property would be added to the new_data JSON payload, and I just didn't like how that looked, so I have extracted it to its own column in the approvals table. This does mean the user needs to run a new migration though when using the next version (should be v1.5.0)

@cjmellor cjmellor self-assigned this Mar 17, 2024
@cjmellor cjmellor added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request labels Mar 17, 2024
@cjmellor cjmellor closed this Mar 18, 2024
@cjmellor cjmellor reopened this Mar 18, 2024
@cjmellor cjmellor marked this pull request as ready for review March 18, 2024 23:27
@cjmellor cjmellor merged commit 4eb0360 into main Mar 18, 2024
5 checks passed
@cjmellor cjmellor deleted the fix/foreign-key-constraint-on-query-builder branch March 18, 2024 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant