-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
DoctrineOrmTypeGuesser throw an exception with embedded class #26543
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
Comments
Hello, can you provide the full exception trace please ? |
@fancyweb : indeed, it is silenced for getting the class metadata but it is not if something happen while trying to get some information on a property. Here is the trace
Here is a part of my "kick fix" in the DoctrineOrmTypeGuesser : use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\Mapping\Embedded;
use Doctrine\Common\Annotations\AnnotationReader;
class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface {
....
/**
* @var AnnotationReader
*/
private $annotation_reader ;
/**
* @return AnnotationReader
*/
public function getAnnotationReader()
{
if ($this->annotation_reader === null)
$this->annotation_reader = new AnnotationReader();
return $this->annotation_reader;
}
protected function getEmbeddedAnnotation($class,$property) {
$rc = new \ReflectionClass($class);
if (!$rc->hasProperty($property)) {
return ;
}
$rc->getProperty($property);
return $this->getAnnotationReader()->getPropertyAnnotation($rp,Embedded::class);
}
/**
* {@inheritdoc}
*/
public function guessMaxLength($class, $property)
{
$ret = $this->getMetadata($class);
if ($ret && $ret[0]->hasField($property) && !$ret[0]->hasAssociation($property)) {
//------- the fix -----
if ($embed = $this->getEmbeddedAnnotation($class,$property))
return ;
// -------------------
$mapping = $ret[0]->getFieldMapping($property);
if (isset($mapping['length'])) {
return new ValueGuess($mapping['length'], Guess::HIGH_CONFIDENCE);
}
if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
}
}
} ( Maybe i have to change VERY_HIGH_CONFIDENCE to a lower value ; it's some vestige when i was trying to see if the guesser chain will stop when a VERY_HIGH_CONFIDENCE is hinted. ) I also got same kind of fix for the guessRequired, guessPattern, etc. methods but i'm not sure about what to return for the required value for an embedded ; i guess required fields are usually inside the embedded form type rather than in the parent container. Well, at least, it is ok for my project :) And yes, i will have to change the code for working when using xml or yaml mapping :] (as i had warned : it's ugly) :/ |
I have checked and IMHO there is a bug. |
… in DoctrineOrmTypeGuesser anymore (fancyweb) This PR was merged into the 2.7 branch. Discussion ---------- [DoctrineBridge] Don't rely on ClassMetadataInfo->hasField in DoctrineOrmTypeGuesser anymore | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26543 | License | MIT | Doc PR | - Discussion and explanations in the linked issue #26543 Commits ------- f656dc2 [DoctrineBridge] Don't rely on ClassMetadataInfo->hasField in DoctrineOrmTypeGuesser anymore
… in DoctrineOrmTypeGuesser anymore (fancyweb) This PR was merged into the 2.7 branch. Discussion ---------- [DoctrineBridge] Don't rely on ClassMetadataInfo->hasField in DoctrineOrmTypeGuesser anymore | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#26543 | License | MIT | Doc PR | - Discussion and explanations in the linked issue symfony/symfony#26543 Commits ------- f656dc2082 [DoctrineBridge] Don't rely on ClassMetadataInfo->hasField in DoctrineOrmTypeGuesser anymore
The use case :
So :
But :
So : that doesn't work
The Exception :
No mapping found for field 'identite' on class 'NSF\CoreBundle\Entity\Client'.
in vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\MappingException.php (line 163)
My solution was to fix (in my way) into the DoctrineOrmTypeGuesser and to use my updated class with composer/autoload/file directive.
The text was updated successfully, but these errors were encountered: