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

Approving a newly created record: Call to a member function applyModificationChanges() #9

Closed
huge10 opened this issue Nov 1, 2019 · 2 comments · Fixed by #16
Closed
Assignees

Comments

@huge10
Copy link

huge10 commented Nov 1, 2019

When a model with RequiredApproval is freshly created, a Modification is created correctly. When I approve it using:

$user->approve($modification);

and since it has 0 remaining approvers left it tries to apply the changes and I get:

Call to a member function applyModificationChanges() on null

which makes sense as here:

$modification->modifiable->applyModificationChanges($modification, true);

I guess there is no 'modifiable' (as the record does not exist yet / has no idea).

Am I missing something here? Love your work, works perfect for changes but I can't seem to get it to work for creations.

@stephenlake
Copy link
Member

Thanks for the report, I'll unfortunately only be able to look into this later this week.

@stephenlake stephenlake self-assigned this Nov 3, 2019
@stephenlake stephenlake added the help wanted Extra attention is needed label Nov 6, 2019
@huge10
Copy link
Author

huge10 commented Nov 6, 2019

I currently do this dirty hack in ApprovesChanges trait (mind you, novice developer):

            if ($modification->approversRemaining == 0) {
                if($modification->modifiable_id === null) {
                    $polymorphicModel = new $modification->modifiable_type();
                    $polymorphicModel->applyModificationChanges($modification, true);
                } else {
                    $modification->modifiable->applyModificationChanges($modification, true);
                }
            }

@stephenlake stephenlake removed the help wanted Extra attention is needed label Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants