Skip to content

[DoctrineBridge] Fix required guess of boolean fields #16302

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

Closed
wants to merge 2 commits into from

Conversation

enumag
Copy link
Contributor

@enumag enumag commented Oct 20, 2015

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

@enumag
Copy link
Contributor Author

enumag commented Oct 20, 2015

Currently boolean fields of Doctrine entities are correctly guessed as checkboxes but incorrectly guessed as required.

@@ -95,7 +95,7 @@ public function guessRequired($class, $property)

// Check whether the field exists and is nullable or not
if ($classMetadata->hasField($property)) {
if (!$classMetadata->isNullable($property)) {
if (!$classMetadata->isNullable($property) && $classMetadata->getTypeOfField($property) !== 'boolean') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use 'boolean' !== $classMetadata->getTypeOfField($property)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right... Forgot about the coding style.

@Tobion
Copy link
Contributor

Tobion commented Oct 22, 2015

Please also refactor guessType to use DBAL constants.

@@ -51,28 +52,28 @@ public function guessType($class, $property)
}

switch ($metadata->getTypeOfField($property)) {
case 'array':
case Type::TARRAY:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add SIMPLE_ARRAY and JSON_ARRAY?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if they work as collection form type as well. So lets do that in another PR if necessary.

return new TypeGuess('checkbox', array(), Guess::HIGH_CONFIDENCE);
case 'datetime':
case Type::DATETIME:
case Type::DATETIMETZ:
case 'vardatetime':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is here. There doesn't seem to be a corresponding type in Doctrine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobion
Copy link
Contributor

Tobion commented Oct 22, 2015

👍 Should be merged in 2.3 by merger!

Status: Reviewed

@enumag
Copy link
Contributor Author

enumag commented Oct 22, 2015

@Tobion Thanks! I refactored guessPattern and guessMaxLength to use the constants as well.

@fabpot
Copy link
Member

fabpot commented Oct 23, 2015

Thank you @enumag.

fabpot added a commit that referenced this pull request Oct 23, 2015
…mag)

This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #16302).

Discussion
----------

[DoctrineBridge] Fix required guess of boolean fields

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

Commits
-------

b21d498 [DoctrineBridge] Fix required guess of boolean fields
@fabpot fabpot closed this Oct 23, 2015
This was referenced Oct 27, 2015
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.

4 participants