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

[9.x] Fix removing queued models with custom Scout keys #480

Merged
merged 6 commits into from
Jun 10, 2021

Conversation

stevebauman
Copy link
Contributor

Purpose

This PR patches the issue described in PR #479.

Description

This PR fixes the issue described above. However, if developers are customizing their Scout key via getScoutKey() and are utilizing queuing, they must also modify the getScoutKeyName() to return the name of this custom key, so that the models can be hydrated and be properly removed from indexes. I can also submit a PR to the docs repo if this gets merged in so it can instruct developers to perform this step when queuing using custom scout keys.

The RemoveableScoutCollection class extends the Eloquent collection class, and pulls the queueable ID's from the model's getScoutKey() method. This is the cleanest solution I was able to come up with the least possible intrusion and work on the developers side.

In regards to the issue posted in the above PR, they would simply have to add this into their model after this patch:

public function getScoutKey()
{
    return $this->custom_id;
}

public function getScoutKeyName()
{
    return $this->qualifyColumn('custom_id');
}

Let me know if there's any issues/comments/concerns with this approach. Thanks for your time! ❤️

@driesvints
Copy link
Member

@stevebauman seems to break the test suite.

@stevebauman
Copy link
Contributor Author

@driesvints Okay we're all set! Fixed the test and style issues 👍

@taylorotwell
Copy link
Member

So does this replace #479?

@stevebauman
Copy link
Contributor Author

So does this replace #479?

Yup it does!

@stevebauman
Copy link
Contributor Author

I see that the docs already contains the recommendation to change the getScoutKeyName() method when using custom Scout keys:

https://laravel.com/docs/8.x/scout#configuring-the-model-id

If you need to customize this behavior, you may override the getScoutKey and the getScoutKeyName methods on the model

So we're good to go on that front as well.

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 this pull request may close these issues.

3 participants