2014-04-23 42 views
0

我有3个实体映射导致一些问题。映射问题Doctrine&Symfony

这两个问题IM饰面是:

  1. 当我使用学说命令行架构更新,它消除在item_type_field表中的列“ITEM_TYPE”。它看起来像教条没有看到YML文件中的这一列,而它在那里。

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

我错过了什么吗?

实体和映射:

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 

回答

0

在TYPEFIELD你有多对一重复两次。第二个压倒第一个,因为教义没有看到它。

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 

这可能会也可能不会解决所有问题。它当然不能解决你非常混乱的命名约定的问题。

+0

Thx我不知道你只需指定“manyToOne:”一次,删除这个固定的主要问题。 – Jeroen