From 9027f367489eb10c0b18d44bbbb62d56a71fefa1 Mon Sep 17 00:00:00 2001 From: kj Date: Sat, 5 Sep 2026 00:39:16 -0300 Subject: [PATCH] refactor(model): use reflection for search field discovery --- src/Libs/Model.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Libs/Model.php b/src/Libs/Model.php index 1861ebe..bfb93dc 100644 --- a/src/Libs/Model.php +++ b/src/Libs/Model.php @@ -1098,8 +1098,18 @@ class Model public static function search(string $search, ?array $in = null): static { if ($in == null) { - $className = get_called_class(); - $in = array_keys((new $className())->getVars()); + $in = []; + $reflection = new \ReflectionClass(get_called_class()); + + foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { + if (!in_array($property->getName(), static::$dbIgnoreSave)) { + $in[] = static::camelCaseToSnakeCase($property->getName()); + } + } + } + + if (empty($in)) { + return new static(); } $search = static::bind($search);