Skip to content

Commit f656dc2

Browse files
committed
[DoctrineBridge] Don't rely on ClassMetadataInfo->hasField in DoctrineOrmTypeGuesser anymore
1 parent e0ff6e0 commit f656dc2

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function guessRequired($class, $property)
9595
$classMetadata = $classMetadatas[0];
9696

9797
// Check whether the field exists and is nullable or not
98-
if ($classMetadata->hasField($property)) {
98+
if (isset($classMetadata->fieldMappings[$property])) {
9999
if (!$classMetadata->isNullable($property) && Type::BOOLEAN !== $classMetadata->getTypeOfField($property)) {
100100
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
101101
}
@@ -124,7 +124,7 @@ public function guessRequired($class, $property)
124124
public function guessMaxLength($class, $property)
125125
{
126126
$ret = $this->getMetadata($class);
127-
if ($ret && $ret[0]->hasField($property) && !$ret[0]->hasAssociation($property)) {
127+
if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) {
128128
$mapping = $ret[0]->getFieldMapping($property);
129129

130130
if (isset($mapping['length'])) {
@@ -143,7 +143,7 @@ public function guessMaxLength($class, $property)
143143
public function guessPattern($class, $property)
144144
{
145145
$ret = $this->getMetadata($class);
146-
if ($ret && $ret[0]->hasField($property) && !$ret[0]->hasAssociation($property)) {
146+
if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) {
147147
if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
148148
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
149149
}

src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ public function requiredProvider()
3333

3434
// Simple field, not nullable
3535
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
36-
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(true));
36+
$classMetadata->fieldMappings['field'] = true;
3737
$classMetadata->expects($this->once())->method('isNullable')->with('field')->will($this->returnValue(false));
3838

3939
$return[] = array($classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE));
4040

4141
// Simple field, nullable
4242
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
43-
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(true));
43+
$classMetadata->fieldMappings['field'] = true;
4444
$classMetadata->expects($this->once())->method('isNullable')->with('field')->will($this->returnValue(true));
4545

4646
$return[] = array($classMetadata, new ValueGuess(false, Guess::MEDIUM_CONFIDENCE));
4747

4848
// One-to-one, nullable (by default)
4949
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
50-
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(false));
5150
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(true));
5251

5352
$mapping = array('joinColumns' => array(array()));
@@ -57,7 +56,6 @@ public function requiredProvider()
5756

5857
// One-to-one, nullable (explicit)
5958
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
60-
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(false));
6159
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(true));
6260

6361
$mapping = array('joinColumns' => array(array('nullable' => true)));
@@ -67,7 +65,6 @@ public function requiredProvider()
6765

6866
// One-to-one, not nullable
6967
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
70-
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(false));
7168
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(true));
7269

7370
$mapping = array('joinColumns' => array(array('nullable' => false)));
@@ -77,7 +74,6 @@ public function requiredProvider()
7774

7875
// One-to-many, no clue
7976
$classMetadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata')->disableOriginalConstructor()->getMock();
80-
$classMetadata->expects($this->once())->method('hasField')->with('field')->will($this->returnValue(false));
8177
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->will($this->returnValue(false));
8278

8379
$return[] = array($classMetadata, null);

0 commit comments

Comments
 (0)