Open adpu opened 2 years ago
This is definitly a bug. I found out that in
TCG\Voyager\Http\Controllers\VoyagerBaseController@index
search keys are taken directly from the field data_rows
.field
.
This means that when searching in browse we will get a query string like this
?key=product_feedbacks_belongsto_product_relationship& filter=contains&s=test
at the same time in the method VoyagerBaseController :: findSearchableRelationshipRow
we check whethersearchKey
matches the column of relationship details
from here
this means that in my case the query string should be
?key=product _id&filter=contains&s=test
product _id
instead of product_feedbacks_belongsto_product_relationship
such changes helped me to solve the problem temporarily
$searchNames = [];
if ($dataType->server_side) {
$searchNames = $dataType->browseRows->mapWithKeys(function ($row) {
$searchKey = $row['field'];
if ($row['type'] == 'relationship') {
$searchKey = $row['details']->column;
}
return [ $searchKey => $row->getTranslatedAttribute('display_name')];
});
}
Thanks, I will study it
Have a nice christmas
El dc., 22 de des. 2021, 18:33, Oleksandr Levytskii < @.***> va escriure:
It is a definitly bug. This is definitly a bug. I found out that in
TCG\Voyager\ @.***
search keys are taken directly from the field data_rows.field.
[image: image] https://user-images.githubusercontent.com/20813103/147129596-cdea9b7a-e3e1-498d-a167-a71b79ea9393.png This means that when searching in browse we will get a query string like this
?key=product_feedbacks_belongsto_product_relationship& filter=contains&s=test
at the same time in the method VoyagerBaseController :: findSearchableRelationshipRow we check whether searchKey matches the column of relationship details [image: image] https://user-images.githubusercontent.com/20813103/147130133-dfe50836-0de3-4b62-8666-da1eaa4a3c26.png
from here
[image: image] https://user-images.githubusercontent.com/20813103/147130729-cfacfacd-999e-405a-a91e-9122f0fa2dba.png
this means that in my case the query string should be
?key=product _id&filter=contains&s=test
product _id instead of product_feedbacks_belongsto_product_relationship
such changes helped me to solve the problem temporarily
if ($dataType->server_side) { $searchNames = $dataType->browseRows->mapWithKeys(function ($row) { $searchKey = $row['field']; if ($row['type'] == 'relationship') { $searchKey = $row['details']->column; } return [ $searchKey => $row->getTranslatedAttribute('display_name')]; }); }```
— Reply to this email directly, view it on GitHub https://github.com/the-control-group/voyager/issues/5449#issuecomment-999749833, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEA6SVDRMOXCJAT2OELUF5DUSIDXPANCNFSM5EXFWH5Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
Laravel version
7.29
PHP version
8.0.10
Voyager version
1.5
Database
Mysql
Description
When I create a relation 'One to Many', after create a relations belongsTo in my bread, in search browse view when I search by relation field, It never show results.
Steps to reproduce
**0- Install fresh laravel and voyager
1- Create 2 tables:
Table Recipes:
`<?php
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema;
class CreateRecipesTable extends Migration { /**
@return void */ public function up() { Schema::create('recipes', function (Blueprint $table) { $table->increments('id'); $table->string('slug'); $table->string('name'); $table->string('duration'); $table->string('level'); $table->string('video_url'); $table->text('ingredients'); $table->text('related')->nullable(); $table->string('image'); $table->string('metatitle'); $table->string('metadescription'); $table->integer('position')->unsigned()->nullable(); $table->enum('status', ['visible', 'novisible']); $table->timestamps(); }); }
/**
Table steps:
`<?php
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema;
class CreateStepsTable extends Migration { /**
@return void */ public function up() { Schema::create('steps', function (Blueprint $table) { $table->increments('id'); $table->integer('recipe_id')->unsigned(); $table->foreign('recipe_id')->references('id')->on('recipes')->onDelete('cascade'); $table->integer('number')->unsigned(); $table->text('text'); $table->string('image')->nullable(); $table->timestamps(); }); }
/**
2 - Create Models of tables
Recipe Model
`<?php
namespace App;
use Illuminate\Database\Eloquent\Model; use Mcamara\LaravelLocalization\Facades\LaravelLocalization; use TCG\Voyager\Traits\Resizable; use TCG\Voyager\Traits\Translatable;
class Recipe extends Model { use Resizable; use Translatable;
} `
Step Model
`<?php
namespace App; use TCG\Voyager\Traits\Translatable; use TCG\Voyager\Traits\Resizable; use Illuminate\Database\Eloquent\Model;
class Step extends Model { use Translatable; use Resizable; protected $translatable = ['text']; protected $table = 'steps';
}`
3. Create Recipe and Step 'Bread'
Inside my Step 'Bread' I create a relation BelongsTo:
4. In my browse view I try to make search by 'recipes_id It not shows results:![image](https://user-images.githubusercontent.com/16902484/134758400-acba7a5c-1398-4449-be47-d680cef63735.png)
In my database i have registers relationed
Expected behavior
The expected behavior will be the following:
Screenshots
No response
Additional context
No response