-
Notifications
You must be signed in to change notification settings - Fork 110
Indexing & Searching Relationships #96
Comments
I think the best workaround is to create a MySQL View. You can then reference the "MySQL View" model (which is still a regular eloquent model, it just points to a view instead of a table), and now you can search across relationships because the view can be built to join the relationships. |
Thanks @wlius-support3 for the idea to use a View. This may help others: I overrode the MainModel.php public static function search($query = '', $callback = null) {
return app(Builder::class, [
'model' => new MainModelSeachView(), // Just this changed from the parent implementation.
'query' => $query,
'callback' => $callback,
'softDelete'=> static::usesSoftDelete() && config('scout.soft_delete', false),
]);
} Then in the View model I overrode MainModelSearchView.php public function newFromBuilder($attributes = [], $connection = NULL) {
return MainModel::find($attributes->id); // Ensure the ID is available in the View table
} This way I can perform a search like Would love to know if there's a better way to do this. |
I am trying to include categories in my search but not getting any results.
I'm searching the main table "Posts" where there is a hasMany relationship to "Categories" and this has a hasOne relationship to "CategoryList" which has the column "name". This name column is the one that I want to include in the index when updating Posts so posts are searchable via the category name.
Is this possible?
The text was updated successfully, but these errors were encountered: