laravel-scout-tntsearch-driver icon indicating copy to clipboard operation
laravel-scout-tntsearch-driver copied to clipboard

Bug with Laravel Scout v6.1.3 update

Open Dylan-Chapman opened this issue 6 years ago • 11 comments

(For more details/discussion: https://github.com/laravel/scout/issues/339)

Lazy loading relationships is no longer working with the latest Laravel Scout. They recommended I open a thread in this repo. They thought it may be related to: https://github.com/teamtnt/laravel-scout-tntsearch-driver/blob/master/src/Engines/TNTSearchEngine.php#L197-L206.

The problem is that

MyModel::search('myQuery')->get()->load('myRelation');

returns the error

Method Illuminate\Support\Collection::load does not exist.

Dylan-Chapman avatar Dec 20 '18 21:12 Dylan-Chapman

Having the same issues. Sometime the get() returns

Illuminate\Support\Collection

and sometimes

Illuminate\Database\Eloquent\Collection

as Illuminate\Support\Collection don't have load method.

ahkmunna avatar Dec 30 '18 17:12 ahkmunna

same problem here

renatosistemasvc avatar Jan 19 '19 17:01 renatosistemasvc

@Dylan-Chapman Can you solve this?

renatosistemasvc avatar Jan 19 '19 21:01 renatosistemasvc

@renatosistemasvc Nope, I had to revert to Laravel Scout v6.1.1 until this is fixed.

Dylan-Chapman avatar Jan 19 '19 22:01 Dylan-Chapman

@Dylan-Chapman I tried to install an earlier version and could not.

Is it possible for you to send me the teamtnt folder that is inside the vendor of your project for me to use here in my project?

I need to put this to work and if you can help me I'll be very happy.

my email: [email protected]

renatosistemasvc avatar Jan 19 '19 22:01 renatosistemasvc

It's not this package you need to revert, it's Scout. Sending the teamtnt folder won't help. Just lock Scout in your composer json: "laravel/scout": "6.1.1" and run a composer install.

Dylan-Chapman avatar Jan 19 '19 22:01 Dylan-Chapman

@Dylan-Chapman your solution worked! Thank you friend!

renatosistemasvc avatar Jan 19 '19 23:01 renatosistemasvc

I was just about to open a support ticket on this same issue, then found this.

I've been looking through code and if I do the following

$results = Collection::make( Entity::search( $query )->get() );
$results->load( 'relationship_name');

it works as a temporary fix. Reviewing code for this project I found the following.

https://github.com/teamtnt/laravel-scout-tntsearch-driver/blob/655d6ead9192d49c58dd85c9de6e53ea5d9cbe25/src/Engines/TNTSearchEngine.php#L201-L206

If I change the linked lines to

return Collection::make($results['ids'])->map(function ($hit) use ($models) {
            if (isset($models[$hit])) {
                return $models[$hit];
            }
        })->filter()->values();

It fixes my issue. I get an instance of "Illuminate\Database\Eloquent\Collection" instead of "Illuminate\Support\Collection" which is what is returned by collect()

I was about to work on a PR as this looked like a fix but saw the following comment so left it be as there could be other implications of this change I'd not considered.

It's not this package you need to revert, it's Scout. Sending the teamtnt folder won't help. Just lock Scout in your composer json: "laravel/scout": "6.1.1" and run a composer install.

ncrewsSouthern avatar Jan 21 '19 22:01 ncrewsSouthern

I just tested, and it seems like this actually broke in v6.1.2, which means it's likely caused by this pull request. So, I think as long as you cross-check any changes from that pull request, it will probably be fine.

(We already established earlier on it was likely from that pull request, but because the error arose between 6.1.1 and 6.1.2, that's almost definitely the problem. I just don't know enough the libraries' internals to do much about it.)

Dylan-Chapman avatar Jan 23 '19 00:01 Dylan-Chapman

This issue still exist in latest version of tntsearch and laravel 6.x.

ahkmunna avatar Jan 09 '20 13:01 ahkmunna

Any update regarding this issue?

ahkmunna avatar Mar 15 '20 19:03 ahkmunna