Skip to content

Commit 8f29c6e

Browse files
committed
refactor: defer camelCase conversion in property lookup
1 parent ba76b9b commit 8f29c6e

1 file changed

Lines changed: 36 additions & 12 deletions

File tree

packages/database/src/Builder/ModelInspector.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function getBelongsTo(string $name): ?BelongsTo
192192
return null;
193193
}
194194

195-
$name = str($name)->camel();
195+
$name = str($name);
196196

197197
$singularizedName = $name->singularizeLastWord();
198198

@@ -201,7 +201,11 @@ public function getBelongsTo(string $name): ?BelongsTo
201201
}
202202

203203
if (! $this->reflector->hasProperty($name)) {
204-
return null;
204+
$name = $name->camel();
205+
206+
if (! $this->reflector->hasProperty($name)) {
207+
return null;
208+
}
205209
}
206210

207211
$property = $this->reflector->getProperty($name);
@@ -256,7 +260,7 @@ public function getHasOne(string $name): ?HasOne
256260
return null;
257261
}
258262

259-
$name = str($name)->camel();
263+
$name = str($name);
260264

261265
$singularizedName = $name->singularizeLastWord();
262266

@@ -265,7 +269,11 @@ public function getHasOne(string $name): ?HasOne
265269
}
266270

267271
if (! $this->reflector->hasProperty($name)) {
268-
return null;
272+
$name = $name->camel();
273+
274+
if (! $this->reflector->hasProperty($name)) {
275+
return null;
276+
}
269277
}
270278

271279
$property = $this->reflector->getProperty($name);
@@ -285,10 +293,14 @@ public function getHasMany(string $name): ?HasMany
285293
return null;
286294
}
287295

288-
$name = str($name)->camel();
296+
$name = str($name);
289297

290298
if (! $this->reflector->hasProperty($name)) {
291-
return null;
299+
$name = $name->camel();
300+
301+
if (! $this->reflector->hasProperty($name)) {
302+
return null;
303+
}
292304
}
293305

294306
$property = $this->reflector->getProperty($name);
@@ -327,7 +339,7 @@ public function getHasOneThrough(string $name): ?HasOneThrough
327339
return null;
328340
}
329341

330-
$name = str($name)->camel();
342+
$name = str($name);
331343

332344
$singularizedName = $name->singularizeLastWord();
333345

@@ -336,7 +348,11 @@ public function getHasOneThrough(string $name): ?HasOneThrough
336348
}
337349

338350
if (! $this->reflector->hasProperty($name)) {
339-
return null;
351+
$name = $name->camel();
352+
353+
if (! $this->reflector->hasProperty($name)) {
354+
return null;
355+
}
340356
}
341357

342358
$property = $this->reflector->getProperty($name);
@@ -356,10 +372,14 @@ public function getHasManyThrough(string $name): ?HasManyThrough
356372
return null;
357373
}
358374

359-
$name = str($name)->camel();
375+
$name = str($name);
360376

361377
if (! $this->reflector->hasProperty($name)) {
362-
return null;
378+
$name = $name->camel();
379+
380+
if (! $this->reflector->hasProperty($name)) {
381+
return null;
382+
}
363383
}
364384

365385
$property = $this->reflector->getProperty($name);
@@ -379,10 +399,14 @@ public function getBelongsToMany(string $name): ?BelongsToMany
379399
return null;
380400
}
381401

382-
$name = str($name)->camel();
402+
$name = str($name);
383403

384404
if (! $this->reflector->hasProperty($name)) {
385-
return null;
405+
$name = $name->camel();
406+
407+
if (! $this->reflector->hasProperty($name)) {
408+
return null;
409+
}
386410
}
387411

388412
$property = $this->reflector->getProperty($name);

0 commit comments

Comments
 (0)