制图问题学说& Symfony的

时间:2014-04-23 19:40:43

标签: php symfony doctrine-orm doctrine yaml

我有3个实体,其中映射导致了一些问题。

我面临的两个问题是:

  1. 当我使用doctrine命令行架构更新时,它会删除item_type_field表中的列“item_type”。看起来教义没有在YML文件中看到这个列,而它就在那里。

  2. 在Symfony应用程序中,TypeField和FieldType之间的映射不起作用。当我转储字段的FieldType时,它返回null。

  3. 我错过了什么吗?

    实体和映射:

    class ItemType
    {
        protected $id;  
        protected $title;
        protected $description;
        protected $fields;
    
    
        public function __construct(){  
             $this->fields = new ArrayCollection();
        }
    
    
        public function getId()
        {
            return $this->id;
        }
    
        public function setTitle($title)
        {
            $this->title = $title;
    
            return $this;
        }
    
        public function getTitle()
        {
            return $this->title;
        }
    
        public function setDescription($description)
        {
            $this->description = $description;
    
            return $this;
        }
    
        public function getDescription()
        {
            return $this->description;
        }   
    
        public function addField(\Aveqcms\CoreBundle\Entity\TypeField $field)
        {
            $field->setItemType($this);
            $this->fields[] = $field;
    
            return $this;
        }
    
        public function removeField(\Aveqcms\CoreBundle\Entity\TypeField $field)
        {
            $this->fields->removeElement($field);
        }
    
        public function getFields()
        {
            return $this->fields;
        }
    }
    
    
    class TypeField
    {
    
        private $id;  
        private $item_type;
        private $field_type;
    
    
        public function getId()
        {
            return $this->id;
        }
    
        public function setItemType($itemType)
        {
            $this->item_type = $itemType;
            return $this;
        }
    
        public function getItemType()
        {
            return $this->item_type;
        }
    
        public function setFieldType($fieldType)
        {
            $this->field_type = $fieldType;
    
            return $this;
        }
    
        public function getFieldType()
        {
            return $this->field_type;
        }
    }
    
    
    class FieldType
    {
    
        private $id;
        private $title; 
        private $fields;
    
        public function __construct()
        {
            $this->fields = new ArrayCollection();
        }   
    
        public function getId()
        {
            return $this->id;
        }
    
        public function setTitle($title)
        {
            $this->title = $title;
            return $this;
        }
    
    
        public function getTitle()
        {
            return $this->title;
        }
    }
    

    映射文件:

    Acme\CoreBundle\Entity\ItemType:
        type: entity
        table: item_type
        id:
            id:
                type: integer
                generator: { strategy: AUTO }
        fields:
            title:
                type: string
                length: 255
            description:
                type: string
                length: 255  
        oneToMany:
            fields:
                targetEntity: TypeField
                mappedBy: item_type
                cascade: [persist]   
    
    Acme\CoreBundle\Entity\TypeField:
        type: entity
        table: item_type_field
        id:
            id:
                type: integer
                generator: { strategy: AUTO }  
        manyToOne:
            field_type:
                targetEntity: FieldType
                inversedBy: fields
                joinColumn:
                    name: field_type
                    referencedColumnName: id        
        manyToOne:
            item_type:
                targetEntity: ItemType
                inversedBy: fields
                joinColumn:
                    name: item_type
                    referencedColumnName: id
    
    Acme\CoreBundle\Entity\FieldType:
        type: entity
        table: field_type
        id:
            id:
                type: integer
                id: true
                generator:
                    strategy: AUTO
        fields:
            title:
                type: text
        oneToMany:
            fields:
                targetEntity: TypeField
                mappedBy: field_type
    

1 个答案:

答案 0 :(得分:0)

在TypeField中,您有多次重复的ToOo重复。第二个覆盖了第一个,这就是为什么教义没有看到它。

Acme\CoreBundle\Entity\TypeField:
type: entity
table: item_type_field
id:
    id:
        type: integer
        generator: { strategy: AUTO }  
manyToOne:
    field_type:
        targetEntity: FieldType
        inversedBy: fields
        joinColumn:
            name: field_type
            referencedColumnName: id        
#manyToOne: *** Get rid of this ***
    item_type:
        targetEntity: ItemType
        inversedBy: fields
        joinColumn:
            name: item_type
            referencedColumnName: id

这可能会也可能不会解决您的所有问题。它当然没有解决你这个令人困惑的命名约定的问题。