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

belongsToManyOfDescendantsAndSelf a not unique #201

Closed
YouMixx opened this issue Sep 25, 2023 · 3 comments
Closed

belongsToManyOfDescendantsAndSelf a not unique #201

YouMixx opened this issue Sep 25, 2023 · 3 comments

Comments

@YouMixx
Copy link

YouMixx commented Sep 25, 2023

belongsToManyOfDescendantsAndSelf returns duplicates.

In my case, there are categories (multi-level) and companies.

When opening a category, I get all companies of a certain category through belongs To Many Of DescendantsAndSelf. But if the company is in the parent and in the child category, it will return twice.

I understand why this is happening. But I think that by default this type of communication should return only unique values.

@staudenmeir
Copy link
Owner

Hi @YouMixx,
You can get unique companies like this:

$uniqueCompanies = $category->companies()->getQuery()->select('companies.*')->distinct()->get();

@YouMixx
Copy link
Author

YouMixx commented Sep 26, 2023

Don't you think it should be enabled by default?

@staudenmeir
Copy link
Owner

It would be a breaking change for existing users to suddenly only return unique results.

Besides that, I wouldn't consider them duplicates. The affected companies are connected to the category on different levels of the hierarchy and are different in that sense. If you have additional columns in the category_company pivot table, they can also be different for "duplicate" companies.

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

No branches or pull requests

2 participants