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

Deleting a JsonModel from a CollectionOfJsonModels doesn't emit deleting or deleted events. #3

Open
jwadhams opened this issue Feb 7, 2024 · 0 comments

Comments

@jwadhams
Copy link
Collaborator

jwadhams commented Feb 7, 2024

JsonModel implements a ->delete() method that emits deleting and deleted Eloquent events, then sets the model to null in the upstream model.

The problem is this won't work of the JsonModel is in a CollectionOfJsonModels, because the collection expects every element to continue to validate as the original model.

$deal->vehicles->find($vin)->delete(); // throws JsonSchemaValidationException : Vehicle contains invalid data!

so instead we've taken to using the very un-Eloquenty approach

$deal->vehicles->forget($vin)->save(); // Works but doesn't emit deleting or deleted events

Proposed Fix:

  • Update ->delete to work for models in a collection.
    • This might mean giving models some way to detect "am part of a collection"
  • Update collection to use ->delete (to get events) under the covers
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

No branches or pull requests

1 participant