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

[5.3] Fix column overlaping on withCount #16895

Merged
merged 2 commits into from
Dec 21, 2016
Merged

[5.3] Fix column overlaping on withCount #16895

merged 2 commits into from
Dec 21, 2016

Conversation

fernandobandeira
Copy link
Contributor

@fernandobandeira fernandobandeira commented Dec 20, 2016

Fixes #16645

$roles = $user->roles()->withCount('permissions')->get()

Current wrong result for this function:

{
    "id": 4,
    "name": "Administrator",
    "description": "Some description here",
    "created_at": "2016-12-20 22:53:47",
    "updated_at": "2016-12-20 22:53:47",
    "role_id": "2",
    "user_id": "9",
    "permissions_count": "4",
    "pivot": {
        "user_id": "9",
        "role_id": "2"
    }
}

New result:

{
    "id": 2,
    "name": "Administrator",
    "description": "Some description here",
    "created_at": "2016-12-20 22:53:47",
    "updated_at": "2016-12-20 22:53:47",
    "permissions_count": "4",
    "pivot": {
        "user_id": "9",
        "role_id": "2"
    }
}

Notice the ID changed and it removed the inner join columns from the query, they are inside the pivot only now...
4 is the id of the role_user table, it was replacing the id of the role generating a wrong result for this query...

Repo for testing purposes:
https://github.com/cabalopolis/with-count-bug.

Not sure maybe we should target 5.4...

@fernandobandeira
Copy link
Contributor Author

Ping @cabalopolis, @KKSzymanowski

@KKSzymanowski
Copy link
Contributor

@fernandobandeira I'll take a look tomorrow morning.

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

Successfully merging this pull request may close these issues.

None yet

3 participants