0
我有3個實體映射導致一些問題。映射問題Doctrine&Symfony
這兩個問題IM飾面是:
當我使用學說命令行架構更新,它消除在item_type_field表中的列「ITEM_TYPE」。它看起來像教條沒有看到YML文件中的這一列,而它在那裏。
在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
Thx我不知道你只需指定「manyToOne:」一次,刪除這個固定的主要問題。 – Jeroen