TitasGailius / nova-search-relations

This package allow you to include relationship columns into Laravel Nova search query.
Other
352 stars 33 forks source link

Nested relationship search is broken in 2.0.0 #31

Closed odinns closed 3 years ago

odinns commented 3 years ago

Nice package! 😊

Trying out your package, I found that nested relationship search is broken in 2.0.0, as it returns Call to undefined relationship [user.country] now.

Works in 1.0.6 though.

chancezeus commented 3 years ago

Confirmed, the "ensureRelationshipExists" method in "RelationSearch" does not take into account nested relations

chancezeus commented 3 years ago

Tried a "quick fix", if you replace the current content (I run php8 so some changes might be required) with the following:

        if (!str_contains($relation, '.')) {
            $query->getRelation($relation);
        }

        $parts = explode('.', $relation);
        $rel = $query;
        while(!empty($parts)) {
            $rel = $rel->getRelation(array_shift($parts));
        }

Then it will be able to resolve the nested relations

brandonb927 commented 3 years ago

We just upgraded to v2.0 recently and got bit by this issue :(

TitasGailius commented 3 years ago

Fixed in https://github.com/TitasGailius/nova-search-relations/tree/2.0.1

brandonb927 commented 3 years ago

Thank you @TitasGailius!