Skip to content

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

Open
@jwadhams

Description

@jwadhams

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions