You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8c6141c
Browse filesBrowse the repository at this point in the historyBrowse files
DefaultEntityMapping: added except map for columns with no camelCase form
Digits have no letter case, so an underscore directly before a digit
(address_2) is not representable in camelCase and mapping validation
rejects such columns. The except option (DI key mapping.except) declares
explicit property-to-column pairs that take precedence over the
conversion in both directions; the validation message now hints at it.
thrownewNette\InvalidStateException("Column '$table.{$column['name']}' cannot be addressed through entity mapping: its property name '$property' translates back to column '$back'. Rename the column or adjust the mapping.");
161
+
$hint = preg_match('#_\d#', $column['name'])
162
+
? "An underscore directly before a digit has no camelCase form; map the column explicitly via the mapping's except option, or rename it."
163
+
: 'Rename the column or adjust the mapping.';
164
+
thrownewNette\InvalidStateException("Column '$table.{$column['name']}' cannot be addressed through entity mapping: its property name '$property' translates back to column '$back'. $hint");
test('an underscore directly before a digit fails with a digit hint', function () {
96
+
$explorer = createExplorer(
97
+
['CREATE TABLE legacy (id INTEGER PRIMARY KEY AUTOINCREMENT, address_2 INT)'],
98
+
camelCase: true,
99
+
);
100
+
Assert::exception(
101
+
fn() => $explorer->table('legacy'),
102
+
Nette\InvalidStateException::class,
103
+
"Column 'legacy.address_2' cannot be addressed through entity mapping: its property name 'address2' translates back to column 'address2'. An underscore directly before a digit has no camelCase form; map the column explicitly via the mapping's except option, or rename it.",
104
+
);
105
+
});
106
+
107
+
108
+
test('except map makes such a column addressable in both directions', function () {
109
+
$explorer = createExplorer(
110
+
['CREATE TABLE legacy (id INTEGER PRIMARY KEY AUTOINCREMENT, address_2 INT)'],
test('except pair whose column collides with a real column fails loudly', function () {
124
+
$explorer = createExplorer(
125
+
['CREATE TABLE digits (id INTEGER PRIMARY KEY AUTOINCREMENT, address2 INT)'],
126
+
camelCase: true,
127
+
except: ['address2' => 'address_2'],
128
+
);
129
+
Assert::exception(
130
+
fn() => $explorer->table('digits'),
131
+
Nette\InvalidStateException::class,
132
+
"Column 'digits.address2' cannot be addressed through entity mapping: its property name 'address2' translates back to column 'address_2'. Rename the column or adjust the mapping.",
133
+
);
134
+
});
135
+
136
+
137
+
test('except map works without camelCase conversion', function () {
138
+
$explorer = createExplorer(
139
+
['CREATE TABLE legacy (id INTEGER PRIMARY KEY AUTOINCREMENT, address_2 INT)'],
0 commit comments