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

Fix deletion of array items #375

Merged

Conversation

RubyRubenstahl
Copy link
Contributor

Problem

The delete operator is used to remove properties from objects and items from arrays. When delete is used on an array, the item is removed, but the array is not re-indexed;

let a=[1,2,3,4];
delete a[1];

// a now equals [1,,3,4]

If deleteByDot is used on an array that subsequently stored through a feathers service, the resulting array in the database (using the mongoose driver, at least) results in the "deleted" item being replaced with null rather than being completely removed.

Proposed Solution

The pull request tests to see if the item to delete is an array. If it is, splice is to remove the array item. Otherwise, delete is used.

Potential Problems

Because this results in different output, it could potentially break code that relies on the current behavior.

@eddyystop
Copy link
Collaborator

Thanks for this PR.

I'm leary of starting to add special cases to the byDot utilities, because this could become neverending. You did the work and added a test, so how can I say no?

@eddyystop eddyystop merged commit b68eb5c into feathersjs-ecosystem:master Apr 12, 2018
@eddyystop
Copy link
Collaborator

Published to npm as v4.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants