Fix data#403: return date, time and datetime as scalar value#18
Open
PhilippGrashoff wants to merge 2 commits intoatk4:developfrom
Open
Fix data#403: return date, time and datetime as scalar value#18PhilippGrashoff wants to merge 2 commits intoatk4:developfrom
PhilippGrashoff wants to merge 2 commits intoatk4:developfrom
Conversation
This is supposed as proposal to fix atk4/data#403 going with the solution @DarkSide666 proposed. This change routs all GET requests (single record and multiple record as well) through exportModel() function, with uses Model->export() while typecasting set to false. This way, date, time and datetime fields are not cast into PHP \DateTime objects, but the values are returned as stored in Persistence. The solution posted here works for the mentioned date/time fields, however I see some problems: 1) what about fields that should get casting? In the end, API should return usable values. E.g about type money? API should return them as formatted to display 2 digits after the dot, shouldnt it? Is this still done? 2) getting a single record should throw an Exception when the requested record is not found. For that, it has to be loaded(). export() in exportModel() loads again, causing an unneccessary DB request.
Collaborator
Author
|
Hi, |
Collaborator
Author
|
Now this is a sensible first proposal. I wonder about two things:
|
romaninsh
approved these changes
Apr 7, 2020
Member
romaninsh
left a comment
There was a problem hiding this comment.
apologies for delay in approval.
abbadon1334
added a commit
that referenced
this pull request
Apr 8, 2020
DarkSide666
requested changes
Apr 8, 2020
| $allowed_fields = $this->getAllowedFields($model, 'read'); | ||
| $data = []; | ||
| // get all field-elements | ||
| foreach ($model->elements as $field => $f) { |
Member
There was a problem hiding this comment.
No this is wrong now. Should use $model->getFields() and that way get rid of instanceof \atk4\data\Field condition and as result this change can be made simpler.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is supposed as proposal to fix atk4/data#403 going with the solution @DarkSide666 proposed.