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

group function accurate? #19

Closed
duclet opened this issue Aug 25, 2020 · 2 comments · Fixed by #20
Closed

group function accurate? #19

duclet opened this issue Aug 25, 2020 · 2 comments · Fixed by #20
Assignees
Labels
bug Something isn't working

Comments

@duclet
Copy link

duclet commented Aug 25, 2020

Steps required to reproduce the problem

  1. Sample array: [['id' => 1, 'name' => 'A'], ['id' => 2, 'name' => 'B'], ['id' => 1, 'name' => 'C']]
  2. Doing Collection::with(arr)->groupBy(function($k, $v) { return $v['id']; })->all()

Expected Result

[ 1 => [ ['id' => 1, 'name' => 'A'], ['id' => 1, 'name' => 'C'] ], 2 => [ ['id' => 2, 'name' => 'B'] ] ]

Actual Result

  • [ 1 => [ ['id' => 1, 'name' => 'A', [ 0 => ['id' => 1, 'name' => 'C'] ] ], 2 => [ ['id' => 2, 'name' => 'B'] ] ]

Maybe my understanding of what the group function is supposed to do is incorrect by I was thinking it is more in line with what I expect the result to be. The problem seems to be that first time value is set, it is set as is. Second time, it is converted to array and then appended which cause the behavior above. So that means right now, the above would only work for simple values and not arrays or objects.

@drupol drupol added the bug Something isn't working label Aug 25, 2020
@drupol drupol self-assigned this Aug 25, 2020
drupol added a commit that referenced this issue Aug 25, 2020
@drupol
Copy link
Collaborator

drupol commented Aug 25, 2020

Dear @duclet ,

Thanks for the very complete bug report.

I just submitted a PR that update the behavior of the Group operation.

Do you mind having a look at it and maybe try it to see if it fits now ?

drupol added a commit that referenced this issue Aug 26, 2020
drupol added a commit that referenced this issue Aug 26, 2020
@drupol
Copy link
Collaborator

drupol commented Aug 26, 2020

PR has been merged closing the issue.

drupol added a commit that referenced this issue Aug 27, 2020
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
None yet
Development

Successfully merging a pull request may close this issue.

2 participants