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

Underscore _.where function return only one item #13049

Open
LionelGuerin opened this issue Mar 4, 2024 · 2 comments
Open

Underscore _.where function return only one item #13049

LionelGuerin opened this issue Mar 4, 2024 · 2 comments
Labels
Milestone

Comments

@LionelGuerin
Copy link

Hi,

I'm using and reproducing this with meteor on Mac (version 14.2.1) and ubuntu (version 20.04.6)

Since Meteor 2.15, with the upgrade of underscore from 1.0.13 to 1.6.1 .

The return of the function _.where(array, {criteriaToFind}) seems to always be the first element to correspond to the search.

In previous meteor versions, the function _.where used to return an array of every items find.

I made a repository to reproduce the problem.

https://github.com/LionelGuerin/meteor_underscore_where

It's composed of three folders to tests with meteor 2.15 , meteor 2.14 and with vanilla underscore NPM.

For meteor 2.15

git clone [email protected]:LionelGuerin/meteor_underscore_where.git

cd underscore_where/meteor_underscore

npm i

meteor

Go to your browser then click on "Click Me"
You should see the following server log

underscoreTest { randomid: '0DVVuahGdr', tofind: true }

For meteor 2.14

git clone [email protected]:LionelGuerin/meteor_underscore_where.git

cd underscore_where/2-14_meteor_underscore

npm i

meteor

Go to your browser then click on "Click Me"
You should see the following server log

underscoreTest [
  { randomid: '0DVVuahGdr', tofind: true },
  { randomid: '6DAPnPUk7k', tofind: true }
]

For vanilla underscore NPM

git clone [email protected]:LionelGuerin/meteor_underscore_where.git

cd underscore_where/2-14_meteor_underscore

npm i

node underscore_vanilla.js

You should see the following log

underscoreTest [
  { randomid: '0DVVuahGdr', tofind: true },
  { randomid: '6DAPnPUk7k', tofind: true }
]

I have seen another underscore issue with _.intersection, but it seems to be a different problem.
If you need any more information, i will be happy to help ;)

@StorytellerCZ StorytellerCZ added this to the Release 2.16 milestone Mar 5, 2024
@allenfuller
Copy link

This hit me too -- lots of places where I was using _.where to filter an array, now they all return an object. Happy to help with a bug fix.

@Grubba27
Copy link
Contributor

Grubba27 commented Apr 8, 2024

In this PR, things changed.

Before, _.where was implemented using either _.filter(returning every item) or with _.find(returning only one, the first that matches)

What you can do is override it like this:

  _.where = function(obj, attrs) {
    return _.filter(obj, _.matches(attrs));
  };

I'll test it here in your repo and leave an edit.

edit:

it works

Screenshot 2024-04-08 at 10 17 00

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

No branches or pull requests

4 participants