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 selecting fields on belongs to many relations #986

Conversation

rasmuscnielsen
Copy link

When using field selection on belongs-to-many relationships, it currently throws an "id in field list is ambiguous" error:

Integrity constraint violation: 1052 Column 'id' in field list is ambiguous (Connection: mysql, SQL: select id, name, pivot_models.test_model_id as pivot_test_model_id, pivot_models.related_through_pivot_model_id as pivot_related_through_pivot_model_id from related_through_pivot_models inner join pivot_models on related_through_pivot_models.id = pivot_models.related_through_pivot_model_id where pivot_models.test_model_id in (1))

This PR fixes that by qualifying relationship fields upon select.

@freekmurze freekmurze merged commit 52749b2 into spatie:main Dec 23, 2024
1 check passed
@freekmurze
Copy link
Member

Thanks!

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.

2 participants