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

Duplicates filter in EagerLoadIterator removes valid paths #39

Closed
tantchen opened this issue Jul 12, 2024 · 2 comments
Closed

Duplicates filter in EagerLoadIterator removes valid paths #39

tantchen opened this issue Jul 12, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@tantchen
Copy link

At this point i have ["station","aircraft","aircraftConfig","person","owner"] in $values because aircraft starts with aircraftConfig the reject callback removes aircraft.

The expected output should be ["aircraft","aircraftConfig","owner","person","station"]
but it is ["aircraftConfig","owner","person","station"] with the result that every aircraft will be fetched with a singe select.

fn($path) => $values->contains(fn($check) => $path !== $check && Str::startsWith($check, $path))

@tantchen
Copy link
Author

tantchen commented Jul 12, 2024

May be a possible fix ...

   /**
     * Get the paths as a collection.
     *
     * Before returning the paths, we filter out any duplicates. For example, if the iterator
     * yields `user` and `user.country`, we only want `user.country` to be in the collection.
     *
     * @return Collection
     */
    public function collect(): Collection
    {
        $values = collect($this);

        return $values->unique()->reject(
            fn ($path) => $values->contains(fn ($check) => $path !== $check && Str::startsWith($check, $path.'.'))
        )->sort()->values();
    }

@lindyhopchris lindyhopchris self-assigned this Aug 21, 2024
@lindyhopchris lindyhopchris added the bug Something isn't working label Aug 21, 2024
@lindyhopchris
Copy link
Contributor

Thanks for reporting, this definitely is a bug. I've added it to the to-do list to address.

@lindyhopchris lindyhopchris moved this from Ready to In progress in Big Board of Everything Oct 13, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in Big Board of Everything Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants