DDC-2147: Custom annotation in MappedSuperclass #2700

Open
opened 2026-01-22 14:01:00 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 15, 2012).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user kluk:

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.

Originally created by @doctrinebot on GitHub (Nov 15, 2012). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user kluk: 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.
admin added the Bug label 2026-01-22 14:01:00 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 15, 2012):

Comment created by kluk:

error log from orm:validate-schema

@doctrinebot commented on GitHub (Nov 15, 2012): Comment created by kluk: error log from orm:validate-schema
Author
Owner

@doctrinebot commented on GitHub (Jan 23, 2013):

Comment created by @ocramius:

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;
}
@doctrinebot commented on GitHub (Jan 23, 2013): Comment created by @ocramius: 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; } ```
Author
Owner

@doctrinebot commented on GitHub (Jan 30, 2013):

Comment created by kluk:

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.

@doctrinebot commented on GitHub (Jan 30, 2013): Comment created by kluk: the same error when using simple annotation. ``` none <?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. ``` none /**** * 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.
Author
Owner

@doctrinebot commented on GitHub (May 4, 2013):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (May 4, 2013): Comment created by @beberlei: Can you put the code of your annotations online? I can't seem to understand why this happens.
Author
Owner

@doctrinebot commented on GitHub (May 7, 2013):

Comment created by kluk:

namespace libs\Doctrine\Annotation\Entity;
use Doctrine\Common\Annotations\Annotation;

/*** @Annotation **/
class CustomMapping extends Annotation
{
    /****
     *
     * @var string
     */
    public $className;
    /****
     * 
     * 
     * @var IQueryable| string
     */
    public $dataSource;
}
@doctrinebot commented on GitHub (May 7, 2013): Comment created by kluk: ``` php namespace libs\Doctrine\Annotation\Entity; use Doctrine\Common\Annotations\Annotation; /*** @Annotation **/ class CustomMapping extends Annotation { /**** * * @var string */ public $className; /**** * * * @var IQueryable| string */ public $dataSource; } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2700