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

Bug with Laravel Scout v6.1.3 update #215

Closed
Dylan-Chapman opened this issue Dec 20, 2018 · 11 comments
Closed

Bug with Laravel Scout v6.1.3 update #215

Dylan-Chapman opened this issue Dec 20, 2018 · 11 comments

Comments

@Dylan-Chapman
Copy link

(For more details/discussion: laravel/scout#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.
@ahkmunna
Copy link

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.

@renatosistemasvc
Copy link

same problem here

@renatosistemasvc
Copy link

@Dylan-Chapman Can you solve this?

@Dylan-Chapman
Copy link
Author

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

@Dylan-Chapman Dylan-Chapman changed the title *Possible* bug with Laravel Scout v6.1.3 update Bug with Laravel Scout v6.1.3 update Jan 19, 2019
@renatosistemasvc
Copy link

@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: renatosistemas.vc@gmail.com

@Dylan-Chapman
Copy link
Author

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.

@renatosistemasvc
Copy link

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

@ncrewsSouthern
Copy link

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.

// sort models by tnt search result set
return collect($results['ids'])->map(function ($hit) use ($models) {
if (isset($models[$hit])) {
return $models[$hit];
}
})->filter()->values();

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.

@Dylan-Chapman
Copy link
Author

Dylan-Chapman commented Jan 23, 2019

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.)

@ahkmunna
Copy link

ahkmunna commented Jan 9, 2020

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

@ahkmunna
Copy link

Any update regarding this issue?

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

5 participants