From 07ae20d7619b6b9b350f57f8fd2e3565a9176179 Mon Sep 17 00:00:00 2001 From: Alex Bucur Date: Thu, 12 Dec 2024 10:31:02 +0100 Subject: [PATCH] fix: allow usage of the main table filtering the fields --- src/Concerns/AddsFieldsToQuery.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Concerns/AddsFieldsToQuery.php b/src/Concerns/AddsFieldsToQuery.php index d9592326..905e1508 100644 --- a/src/Concerns/AddsFieldsToQuery.php +++ b/src/Concerns/AddsFieldsToQuery.php @@ -42,7 +42,12 @@ protected function addRequestedModelFieldsToQuery(): void $fields = $fields->mapWithKeys(fn ($fields, $table) => [$table => collect($fields)->map(fn ($field) => Str::snake($field))->toArray()]); } - $modelFields = $fields->has($modelTableName) ? $fields->get($modelTableName) : $fields->get('_'); + // Apply additional table name conversion based on strategy + if (config('query-builder.convert_relation_table_name_strategy', false) === 'camelCase') { + $modelFields = $fields->has(Str::camel($modelTableName)) ? $fields->get(Str::camel($modelTableName)) : $fields->get('_'); + } else { + $modelFields = $fields->has($modelTableName) ? $fields->get($modelTableName) : $fields->get('_'); + } if (empty($modelFields)) { return;