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

Filter Relationship MorphTo, HasOne... #88

Open
alansgonzaga opened this issue Oct 10, 2024 · 2 comments
Open

Filter Relationship MorphTo, HasOne... #88

alansgonzaga opened this issue Oct 10, 2024 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@alansgonzaga
Copy link

Sorry if I shouldn't open a new issue, don't know how works but I couldn't reopen #23 issue that I guess is "same problem"

I'm struggling with some relationship filters. In short, I'm having trouble filtering relationships (One to Many (Polymorphic) [morphTo]). I did a lot of debugging of the SQL query that was being executed and I saw that the morphTo relationship was never used. So I came here to look for issues, and I believe it seems to be related to #23 issue. I saw that they said that the HasOne relationship is also not recognized. Since they said that this would be fixed in the future, I did some tests here with a HasOne, but I don't think it works yet, right?

I refactored my production environment to use purity filters, and I'd like to take this opportunity to say that the package is amazing. Unfortunately, I didn't notice that this type of relationship stopped working. It used to work with my old strategy (https://github.com/savannabits/primevue-datatables).

I've tried with and without filling in the $filterFields, I've also made sure that all relationships have the return type filled in, and the Models use the Filterable trait.

I'd like to check if I'm doing something wrong or if it really is a current limitation?
image
image
image
image

@alansgonzaga
Copy link
Author

alansgonzaga commented Oct 12, 2024

I made myself a temporary fix
image
image
image
image

@abbasudo
Copy link
Owner

Hey @alansgonzaga. Thank you for reaching out and providing detailed information about the issue.

The issue with hasOne at #23 has been fixed. However, your issue is interesting. The main reason for that bug is at this line where we try to get the related model by getRelated() function. This function returns the same model for morphTo relations, which makes sense because morph relations have multiple models related instead of a single model. So it returns Compra in your case. It should be returning the related model for Purity to work. Without the related technicality, it should work. However, we can't validate, restrict, and rename fields (columns) of related models because we can't access them.

I'm labeling this as a bug to be fixed in future PRs.

For now, if the temporary fix you provided works, please continue using it while we look into this more. If you have any additional information or further questions, feel free to add them here. We appreciate your patience and understanding. Thank you for using the Laravel Purity package!

@abbasudo abbasudo added bug Something isn't working help wanted Extra attention is needed labels 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 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants