-
Notifications
You must be signed in to change notification settings - Fork 908
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] Not auto appended attributes not working with fetch #5716
Comments
Any thoughts about this one? |
Hey @WrdVdb sorry this one slipped through the cracks. I've added the ability to define the Please allow our private repository to fetch the updated version and you should be able to get 2.2.30 of backpack/pro that has that feature. Cheers |
@pxpm Tested and everthing works perfectly! Thanks for the update. |
@pxpm After using this for a while, one thing would be very useful. We can now show the correct attribute, but we cannot search it as a whole. For example (fictive example) We have a product dropdown with a product with the unique code 'ABC-PROD01' where ABC is the code of the producttype and PROD01 is the productcode, the combination is unique. Everywhere the product should be shown as 'ABC-PROD01'. We can search PROD01, or even ABC when using a join in de query of the fetch. But we cannot find the product when searching for the complete code 'ABC-PROD01'. I fixed this locally by adding
But then I get a error on $model_instance->getColumnType($searchColumn); By checking if the $searchColumn is a string before this function, the problem is solved:
Or maybe add the check in the getColumnType function? Is it possible to add this? Thanks in advance! |
Hey @WrdVdb thanks for the suggestion. I was about to do this change, but while testing my solution I think it's not needed as you can convert the raw expression in a string by yourself. Something like: \Illuminate\Support\Facades\DB::raw("concat(producttypes.code,'-',products.code)")->getValue(\Illuminate\Support\Facades\DB::getQueryGrammar()) Alternatively, you can write the plain string ? Cheers |
Hey @pxpm , I tried this but this gives the following error:
These columns in the array are not raw, but escaped? |
Thanks @WrdVdb I've added the ability for you to use raw expressions 🙏 Hope everything is working as intended now 👍 Please allow a few moments for our private repository to pick the changes and you can get 2.2.32 of backpack/pro with the fix. Cheers |
Bug report
What I did
I added a relationship field using the fetch, but I wanted to show an attribute of the model not an actual field in the database. This does not work because the select blade is using pluck.
I could fix this using the $appends to add the 'extra_attribute_on_the_model' on the model, but this is a huge overhead because of the extra joins.
What I expected to happen
Be able to use attributes in the fetch on the field.
What happened
The field tries to pluck the attribute, but this does not exist.
What I've already tried to fix it
I modified the vendor/backpack/pro/src/Http/Controllers/Operations/FetchOperation.php with an extra config 'attributes':
I added the fetchGet function to remove redundancy (search vs no search)
If I add the 'extra_attribute_on_the_model' or multiple attributes ['extra_attribute_on_the_model','another_extra_attribute_on_the_model'] to the fetch config, this now works with mapping the extra attribute to the result collection.
Backpack, Laravel, PHP, DB version
When I run
php artisan backpack:version
the output is:The text was updated successfully, but these errors were encountered: