-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ORM: Case-insensitive column map option #11802
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b25cda2
ORM: Case-insensitive column map option
Skydev0h fe35d33
ORM: Case-insensitive column map option
Skydev0h e99bd43
Merge remote-tracking branch 'origin/2.1.x-orm-colmap-ci' into 2.1.x-…
Skydev0h cf47d96
Fix indentation of config.json
Skydev0h File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -493,6 +493,20 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface | |
return this; | ||
} | ||
|
||
/** | ||
* Attempts to find key case-insensitively | ||
*/ | ||
private static function columnMapCIResolve(var columnMap, var key) -> string | ||
{ | ||
var cmKey; | ||
for cmKey in array_keys(columnMap) { | ||
if strtolower(cmKey) == strtolower(key) { | ||
return cmKey; | ||
} | ||
} | ||
return key; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For indents we use tabs in zep files instead of spaces There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sergeyklay I think in zep diffs the tabs are there already :) |
||
|
||
/** | ||
* Assigns values to a model from an array returning a new model. | ||
* | ||
|
@@ -530,6 +544,11 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface | |
continue; | ||
} | ||
|
||
// Try to find case-insensitive key variant | ||
if !isset columnMap[key] && globals_get("orm.try_ci_column_map") { | ||
let key = self::columnMapCIResolve(columnMap, key); | ||
} | ||
|
||
// Every field must be part of the column map | ||
if !fetch attribute, columnMap[key] { | ||
if !globals_get("orm.ignore_unknown_columns") { | ||
|
@@ -638,6 +657,11 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface | |
if typeof key == "string" { | ||
if typeof columnMap == "array" { | ||
|
||
// Try to find case-insensitive key variant | ||
if !isset columnMap[key] && globals_get("orm.try_ci_column_map") { | ||
let key = self::columnMapCIResolve(columnMap, key); | ||
} | ||
|
||
/** | ||
* Every field must be part of the column map | ||
*/ | ||
|
@@ -3612,6 +3636,11 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface | |
continue; | ||
} | ||
|
||
// Try to find case-insensitive key variant | ||
if !isset columnMap[key] && globals_get("orm.try_ci_column_map") { | ||
let key = self::columnMapCIResolve(columnMap, key); | ||
} | ||
|
||
/** | ||
* Every field must be part of the column map | ||
*/ | ||
|
@@ -4406,6 +4435,12 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface | |
* Check if the columns must be renamed | ||
*/ | ||
if typeof columnMap == "array" { | ||
|
||
// Try to find case-insensitive attribute variant | ||
if !isset columnMap[attribute] && globals_get("orm.try_ci_column_map") { | ||
let attribute = self::columnMapCIResolve(columnMap, attribute); | ||
} | ||
|
||
if !fetch attributeField, columnMap[attribute] { | ||
if !globals_get("orm.ignore_unknown_columns") { | ||
throw new Exception("Column '" . attribute . "' doesn't make part of the column map"); | ||
|
@@ -4454,7 +4489,8 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface | |
{ | ||
var disableEvents, columnRenaming, notNullValidations, | ||
exceptionOnFailedSave, phqlLiterals, virtualForeignKeys, | ||
lateStateBinding, castOnHydrate, ignoreUnknownColumns; | ||
lateStateBinding, castOnHydrate, ignoreUnknownColumns, | ||
tryCIColumnMap; | ||
|
||
/** | ||
* Enables/Disables globally the internal events | ||
|
@@ -4518,6 +4554,13 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface | |
if fetch ignoreUnknownColumns, options["ignoreUnknownColumns"] { | ||
globals_set("orm.ignore_unknown_columns", ignoreUnknownColumns); | ||
} | ||
|
||
/** | ||
* Allows to try to find attributes in column map case-insensitively (needed for Oracle) | ||
*/ | ||
if fetch tryCIColumnMap, options["tryCIColumnMap"] { | ||
globals_set("orm.try_ci_column_map", tryCIColumnMap); | ||
} | ||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix please indents