Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add "input" option to NumberType #30893

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

Merged
merged 3 commits into from
Apr 6, 2019
Merged

Conversation

webmozart
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #24793
License MIT
Doc PR TODO

This PR replaces #24793 in (partially) fixing how Doctrine's DECIMAL type is handled by the Form component.

Previously, DECIMAL was mapped to the regular NumberType. That confuses Doctrine's change detection, depending on the DB platform.

Examples:

DB DB value Doctrine entity before submit Form input Doctrine entity after submit
SQLite 8.000 '8' 8 8
SQLite 8.123 '8.123' 8.123 8.123
PostgreSQL 8.000 '8.000' 8 8
PostgreSQL 8.123 '8.123' 8.123 8.123

The value in the Doctrine entity changes before and after submit. Hence Doctrine believes an update is necessary.

This PR introduces an input option to NumberType (similar to DateType), that can be set to 'number' (default) or 'string'. If set to 'string', the conversion is as follows:

DB DB value Doctrine entity before submit Form input Doctrine entity after submit
SQLite 8.000 '8' 8 '8.000'
SQLite 8.123 '8.123' 8.123 '8.123'
PostgreSQL 8.000 '8.000' 8 '8.000'
PostgreSQL 8.123 '8.123' 8.123 '8.123'

You see that this does not completely solve this issue for SQLite. However, @Ocramius and I agree that this is something to be fixed by Doctrine, since Doctrine is providing the database abstraction.

That fix should be done in the SqlitePlatform object in Doctrine as part of another PR and should be backwards compatible with the current Doctrine version (i.e. opt in via configuration).

Compared to #24793, this PR does not introduce a new type but instead makes the NumberType more flexible. Also, this PR does not introduce the force_full_scale option since that should be solved by Doctrine as described above.

@chalasr
Copy link
Member

chalasr commented Apr 6, 2019

Can you add a note in the Bridge CHANGELOG?

@webmozart
Copy link
Contributor Author

@chalasr Thanks for the heads up, done.

@xabbuh
Copy link
Member

xabbuh commented Apr 6, 2019

documentation PR added in symfony/symfony-docs#11314

@yceruto
Copy link
Member

yceruto commented Apr 6, 2019

Well, I guess that duplicated reviews will happen all the time, I'm sorry :)

@webmozart webmozart force-pushed the number-type-input branch from 735252b to a99ad37 Compare April 6, 2019 14:46
@webmozart webmozart force-pushed the number-type-input branch from a99ad37 to 3f25734 Compare April 6, 2019 14:48
@fabpot
Copy link
Member

fabpot commented Apr 6, 2019

Thank you @webmozart.

@fabpot fabpot merged commit 3f25734 into symfony:master Apr 6, 2019
fabpot added a commit that referenced this pull request Apr 6, 2019
…chussek)

This PR was merged into the 4.3-dev branch.

Discussion
----------

Add "input" option to NumberType

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24793
| License       | MIT
| Doc PR        | TODO

This PR replaces #24793 in (partially) fixing how Doctrine's DECIMAL type is handled by the Form component.

Previously, DECIMAL was mapped to the regular NumberType. That confuses Doctrine's change detection, depending on the DB platform.

Examples:

| DB | DB value | Doctrine entity before submit | Form input | Doctrine entity after submit
| --- | --- | --- | --- | ---
| SQLite | 8.000 | '8' | 8 | 8
| SQLite | 8.123 | '8.123' | 8.123 | 8.123
| PostgreSQL | 8.000 | '8.000' | 8 | 8
| PostgreSQL | 8.123 | '8.123' | 8.123 | 8.123

The value in the Doctrine entity changes before and after submit. Hence Doctrine believes an update is necessary.

This PR introduces an `input` option to NumberType (similar to DateType), that can be set to `'number'` (default) or `'string'`. If set to `'string'`, the conversion is as follows:

| DB | DB value | Doctrine entity before submit | Form input | Doctrine entity after submit
| --- | --- | --- | --- | ---
| SQLite | 8.000 | **'8'** | 8 | **'8.000'**
| SQLite | 8.123 | '8.123' | 8.123 | '8.123'
| PostgreSQL | 8.000 | '8.000' | 8 | '8.000'
| PostgreSQL | 8.123 | '8.123' | 8.123 | '8.123'

You see that this does not completely solve this issue for SQLite. However, @Ocramius and I agree that this is something to be fixed by Doctrine, since Doctrine is providing the database abstraction.

That fix should be done in the SqlitePlatform object in Doctrine as part of another PR and should be backwards compatible with the current Doctrine version (i.e. opt in via configuration).

Compared to #24793, this PR does not introduce a new type but instead makes the NumberType more flexible. Also, this PR does not introduce the `force_full_scale` option since that should be solved by Doctrine as described above.

Commits
-------

3f25734 Added new option "input" to NumberType
fb2b37a add force_full_scale option to handle all cases
40f2512 [DoctrineBridge] Add decimal form type
wouterj added a commit to symfony/symfony-docs that referenced this pull request Apr 7, 2019
This PR was merged into the master branch.

Discussion
----------

document the input option of the NumberType

see symfony/symfony#30893

#FOSSHackathons #EUFOSSA

Commits
-------

c004dc5 document the input option of the NumberType
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants