Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2147

Custom annotation in MappedSuperclass

    Details

    • Type: Bug Bug
    • Status: Awaiting Feedback
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.1
    • Fix Version/s: None
    • Component/s: Mapping Drivers, ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Linux 3.6.6-1.fc17.x86_64

      Description

      When you try use custom annotation in mappedsuperclass like here http://pastebin.com/YMxKvcLk and then i try get metadata for class i get this error
      Undefined index: fieldName
      ClassMetadataInfo.php function addInheritedFieldMapping
      Problem is that custom annotation doesnt have fieldName.
      Quick fix is add condition to test if fieldName isset.

        Activity

        kluk created issue -
        Hide
        kluk added a comment -

        error log from orm:validate-schema

        Show
        kluk added a comment - error log from orm:validate-schema
        kluk made changes -
        Field Original Value New Value
        Attachment error.log [ 11349 ]
        Hide
        Marco Pivetta added a comment -

        Copying from pastebin:

        use \Doctrine\ORM\Mapping as ORM;
        use \xxx\Doctrine\Annotation\Entity as re;
        use \xxx\Doctrine\Annotation\Forms as rf;
        use \Doctrine\Common\Collections;
         
        /**
         * @ORM\Entity
         */
        class EventPicture extends \Picture
        {
         
            /**
             * @ORM\ManyToOne(targetEntity="Event", inversedBy="eventPicture")
             * @ORM\JoinColumn(name="FK_Event", referencedColumnName="id")
             */
            protected $event;
         
        }
        
        use \Doctrine\ORM\Mapping as ORM;
        use \xxx\Doctrine\Annotation\Entity as re;
        use \xxx\Doctrine\Annotation\Forms as rf;
        use \Doctrine\Common\Collections;
         
        /** @ORM\MappedSuperclass */
        class Picture extends \xxx\Doctrine\Entity\BaseEntity
        {
         
            /**
             * @ORM\Id
             * @ORM\Column(type="integer")
             * @ORM\GeneratedValue(strategy="IDENTITY")
             * @var type
             */
            protected $id;
         
            /**
             * @ORM\Column(type="string",unique=true, nullable=false)
             *  @rf\FileUpload(fileSize="php",uploadType="local",fieldName="link",formControl="FileUploadField",image=true)
             *
             */
            protected $link;
         
        }
        

        kluk does this happen also with any other simple custom annotation? For example following:

        /**
         * @Annotation 
         * @Target({"PROPERTY","ANNOTATION"})
         */
        final class Entity implements Annotation
        {
            /**
             * @var string
             */
            public $value;
        }
        
        Show
        Marco Pivetta added a comment - Copying from pastebin: use \Doctrine\ORM\Mapping as ORM; use \xxx\Doctrine\Annotation\Entity as re; use \xxx\Doctrine\Annotation\Forms as rf; use \Doctrine\Common\Collections; /** * @ORM\Entity */ class EventPicture extends \Picture { /** * @ORM\ManyToOne(targetEntity= "Event" , inversedBy= "eventPicture" ) * @ORM\JoinColumn(name= "FK_Event" , referencedColumnName= "id" ) */ protected $event; } use \Doctrine\ORM\Mapping as ORM; use \xxx\Doctrine\Annotation\Entity as re; use \xxx\Doctrine\Annotation\Forms as rf; use \Doctrine\Common\Collections; /** @ORM\MappedSuperclass */ class Picture extends \xxx\Doctrine\Entity\BaseEntity { /** * @ORM\Id * @ORM\Column(type= "integer" ) * @ORM\GeneratedValue(strategy= "IDENTITY" ) * @ var type */ protected $id; /** * @ORM\Column(type= "string" ,unique= true , nullable= false ) * @rf\FileUpload(fileSize= "php" ,uploadType= "local" ,fieldName= "link" ,formControl= "FileUploadField" ,image= true ) * */ protected $link; } kluk does this happen also with any other simple custom annotation? For example following: /** * @Annotation * @Target({ "PROPERTY" , "ANNOTATION" }) */ final class Entity implements Annotation { /** * @ var string */ public $value; }
        Marco Pivetta made changes -
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        Marco Pivetta made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        Hide
        kluk added a comment -

        the same error when using simple annotation.

         
        <?php
        
        use \Doctrine\ORM\Mapping as ORM;
        use \xxx\Doctrine\Annotation\Entity as re;
        use \xxx\Doctrine\Annotation\Forms as rf;
        use \Doctrine\Common\Collections;
        
        /** @ORM\MappedSuperclass */
        class Picture extends \xxx\Doctrine\Entity\BaseEntity {
        
            /**
             * @ORM\Id
             * @ORM\Column(type="integer")
             * @ORM\GeneratedValue(strategy="IDENTITY")
             * @var type
             */
            protected $id;
        
           
            /**
             * @ORM\Column(type="integer")
             * @rf\SetClass({"class","hide"})
             */
            public $value;
        
            /**
             * @ORM\Column(type="string",unique=true, nullable=true)
             * @rf\FileUpload(fileSize="php",uploadType="local",fieldName="link",formControl="FileUploadField",image=true)
             *
             */
            protected $link;
        
        }
        

        When i remove $value , $picture from class everything goes ok.
        Easy fix for me is change ClassMetadataInfo.

            /**
             * INTERNAL:
             * Adds a field mapping without completing/validating it.
             * This is mainly used to add inherited field mappings to derived classes.
             *
             * @param array $fieldMapping
             *
             * @return void
             */
            public function addInheritedFieldMapping(array $fieldMapping)
            {
                if(isset($fieldMapping['fieldName'])){
                $this->fieldMappings[$fieldMapping['fieldName']] = $fieldMapping;
                $this->columnNames[$fieldMapping['fieldName']] = $fieldMapping['columnName'];
                $this->fieldNames[$fieldMapping['columnName']] = $fieldMapping['fieldName'];
                }
            }
        

        But i dont know if this fix can break another part of doctrine.

        Show
        kluk added a comment - the same error when using simple annotation. <?php use \Doctrine\ORM\Mapping as ORM; use \xxx\Doctrine\Annotation\Entity as re; use \xxx\Doctrine\Annotation\Forms as rf; use \Doctrine\Common\Collections; /** @ORM\MappedSuperclass */ class Picture extends \xxx\Doctrine\Entity\BaseEntity { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="IDENTITY") * @var type */ protected $id; /** * @ORM\Column(type="integer") * @rf\SetClass({"class","hide"}) */ public $value; /** * @ORM\Column(type="string",unique=true, nullable=true) * @rf\FileUpload(fileSize="php",uploadType="local",fieldName="link",formControl="FileUploadField",image=true) * */ protected $link; } When i remove $value , $picture from class everything goes ok. Easy fix for me is change ClassMetadataInfo. /** * INTERNAL: * Adds a field mapping without completing/validating it. * This is mainly used to add inherited field mappings to derived classes. * * @param array $fieldMapping * * @return void */ public function addInheritedFieldMapping(array $fieldMapping) { if(isset($fieldMapping['fieldName'])){ $this->fieldMappings[$fieldMapping['fieldName']] = $fieldMapping; $this->columnNames[$fieldMapping['fieldName']] = $fieldMapping['columnName']; $this->fieldNames[$fieldMapping['columnName']] = $fieldMapping['fieldName']; } } But i dont know if this fix can break another part of doctrine.
        Hide
        Benjamin Eberlei added a comment -

        Can you put the code of your annotations online? I can't seem to understand why this happens.

        Show
        Benjamin Eberlei added a comment - Can you put the code of your annotations online? I can't seem to understand why this happens.
        Hide
        kluk added a comment -
        Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
         
        namespace libs\Doctrine\Annotation\Entity;
        use Doctrine\Common\Annotations\Annotation;
        
        /** @Annotation */
        class CustomMapping extends Annotation
        {
            /**
             *
             * @var string
             */
            public $className;
            /**
             * 
             * 
             * @var IQueryable| string
             */
            public $dataSource;
        }
        
        Show
        kluk added a comment - Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml namespace libs\Doctrine\Annotation\Entity; use Doctrine\Common\Annotations\Annotation; /** @Annotation */ class CustomMapping extends Annotation { /** * * @ var string */ public $className; /** * * * @ var IQueryable| string */ public $dataSource; }

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2147, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            kluk
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: