Bug
When $autoMap = true, the ORM's snakeToCamel() conversion produces incorrect property names for uppercase column names, which is the default for Firebird (and also common in Oracle).
Example
Firebird returns columns like ACCOUNTNO, STORENAME, CREDITLIMIT. The snakeToCamel() method applies lcfirst() which lowercases only the first character:
ACCOUNTNO → aCCOUNTNO
STORENAME → sTORENAME
CREDITLIMIT → cREDITLIMIT
Resulting fieldMapping:
[fieldMapping] => Array
(
[aCCOUNTNO] => ACCOUNTNO
[sTORENAME] => STORENAME
)
These mapped property names (aCCOUNTNO) don't match any declared PHP properties on the model, so the mapping is useless.
Root Cause
snakeToCamel() on line 98 of ORM.php:
private static function snakeToCamel(string $name): string
{
return lcfirst(str_replace('_', '', ucwords($name, '_')));
}
This assumes columns are snake_case (e.g., credit_limit). It doesn't handle:
- ALL-CAPS columns (
ACCOUNTNO, CREDIT_LIMIT) — common in Firebird, Oracle
- Single-word uppercase (
STORENAME) — no underscores to split on
Suggested Fix
snakeToCamel() should lowercase the input first before applying the conversion:
private static function snakeToCamel(string $name): string
{
return lcfirst(str_replace('_', '', ucwords(strtolower($name), '_')));
}
This produces:
ACCOUNTNO → accountno
STORENAME → storename
CREDIT_LIMIT → creditLimit
FIRST_NAME → firstName
Similarly, camelToSnake() may need to handle the reverse — when writing back to Firebird, column names should be uppercased:
private static function camelToSnake(string $name): string
{
return strtolower(preg_replace('/[A-Z]/', '_$0', lcfirst($name)));
}
This already lowercases, but the generated mapping value should match the DB's actual casing. A possible improvement would be to preserve the original column casing from the DB result rather than assuming lowercase.
Environment
- PHP 8.4.8
- Tina4 v3.10.49
- Firebird 4.0 (returns all-uppercase column names by default)
Bug
When
$autoMap = true, the ORM'ssnakeToCamel()conversion produces incorrect property names for uppercase column names, which is the default for Firebird (and also common in Oracle).Example
Firebird returns columns like
ACCOUNTNO,STORENAME,CREDITLIMIT. ThesnakeToCamel()method applieslcfirst()which lowercases only the first character:Resulting
fieldMapping:These mapped property names (
aCCOUNTNO) don't match any declared PHP properties on the model, so the mapping is useless.Root Cause
snakeToCamel()on line 98 ofORM.php:This assumes columns are
snake_case(e.g.,credit_limit). It doesn't handle:ACCOUNTNO,CREDIT_LIMIT) — common in Firebird, OracleSTORENAME) — no underscores to split onSuggested Fix
snakeToCamel()should lowercase the input first before applying the conversion:This produces:
Similarly,
camelToSnake()may need to handle the reverse — when writing back to Firebird, column names should be uppercased:This already lowercases, but the generated mapping value should match the DB's actual casing. A possible improvement would be to preserve the original column casing from the DB result rather than assuming lowercase.
Environment