Php 复合标识符,但使用ID生成器而不是手动分配+;Symfony2
我有三张桌子Php 复合标识符,但使用ID生成器而不是手动分配+;Symfony2,php,mysql,sql,symfony,doctrine-orm,Php,Mysql,Sql,Symfony,Doctrine Orm,我有三张桌子 项目带字段 PK id title description type created delete fk user_id PK item_id (one-to-one with item table), body PK id FK item_id (many-to-one with item table) url type mimetype isextern
项目
带字段
PK id
title
description
type
created
delete
fk user_id
PK item_id (one-to-one with item table),
body
PK id
FK item_id (many-to-one with item table)
url
type
mimetype
isexternal
文章
带字段
PK id
title
description
type
created
delete
fk user_id
PK item_id (one-to-one with item table),
body
PK id
FK item_id (many-to-one with item table)
url
type
mimetype
isexternal
媒体
带字段
PK id
title
description
type
created
delete
fk user_id
PK item_id (one-to-one with item table),
body
PK id
FK item_id (many-to-one with item table)
url
type
mimetype
isexternal
文章
表中的类型
字段是一个枚举,其值为项目、文章和图像
实体是自动生成的。因此,最初项目实体并不扩展项目实体。我必须改变这一点 我总是会遇到这样的错误:
Entity 'Beachteam\BeachteamBundle\Entity\Article' has a composite identifier
but uses an ID generator other than manually assigning (Identity, Sequence).
This is not supported.
Property Beachteam\BeachteamBundle\Entity\Item::$type does not exist
更新:删除我的类型变量并修复discriminatormap后,我出现以下错误:
Entity 'Beachteam\BeachteamBundle\Entity\Article' has a composite identifier
but uses an ID generator other than manually assigning (Identity, Sequence).
This is not supported.
Property Beachteam\BeachteamBundle\Entity\Item::$type does not exist
这是我更新的项目实体:
<?php
namespace Beachteam\BeachteamBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Item
*
* @ORM\Table(name="item", indexes={@ORM\Index(name="fk_item_user1_idx", columns={"user_id"})})
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({
* "ITEM"="Beachteam\BeachteamBundle\Entity\Item",
* "ARTICLE"="Beachteam\BeachteamBundle\Entity\Article",
* "IMAGE"="Beachteam\BeachteamBundle\Entity\Media"
* })
*/
class Item
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255, nullable=false)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @var \DateTime
*
* @ORM\Column(name="created", type="datetime", nullable=false)
*/
private $created;
/**
* @var \DateTime
*
* @ORM\Column(name="deleted", type="datetime", nullable=true)
*/
private $deleted;
/**
* @var \Beachteam\BeachteamBundle\Entity\User
*
* @ORM\ManyToOne(targetEntity="Beachteam\BeachteamBundle\Entity\User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Item
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set description
*
* @param string $description
* @return Item
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set created
*
* @param \DateTime $created
* @return Item
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set deleted
*
* @param \DateTime $deleted
* @return Item
*/
public function setDeleted($deleted)
{
$this->deleted = $deleted;
return $this;
}
/**
* Get deleted
*
* @return \DateTime
*/
public function getDeleted()
{
return $this->deleted;
}
/**
* Set user
*
* @param \Beachteam\BeachteamBundle\Entity\User $user
* @return Item
*/
public function setUser(User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \Beachteam\BeachteamBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
}
我认为您计划了Item::$type属性,同时将条令作为继承属性生成。但这也是通过注释创建的:
@ORM\DiscriminatorColumn(name=“type”,type=“string”)
表键和字段的一部分具有相同的名称。尝试删除类属性(和getter、setter方法),然后更新模式
php应用程序/控制台原则:模式:更新--force
在这次改变之后,你的课程就像我盒子上的一个符咒
祝你好运 我认为这一行(在项目中
):
应该是:
/**
* @ORM\DiscriminatorMap({"ITEM"="Item", "ARTICLE"="Article", "IMAGE"="Media"})
* ^
*/
我不是很确定,但可能是鉴别器映射需要完全限定的类名:
/**
* @ORM\DiscriminatorMap({
* "ITEM"="Beachteam\BeachteamBundle\Entity\Item",
* "ARTICLE"="Beachteam\BeachteamBundle\Entity\Article",
* "IMAGE"="Beachteam\BeachteamBundle\Entity\Media"
* })
*/
接下来,您需要从项
中删除属性$type
,因为类型
已用作鉴别器列
您可能还希望使用控制台验证映射:
app/console doctrine:schema:validate
修复所有可能报告的错误
更新
属性Beachteam\BeachteamBundle\Entity\Item::$type不存在
这意味着在代码中的某个地方,类项的$type
属性(现在不存在)仍在使用。你得找出在哪里
- 在代码中搜索
->类型
- 清除缓存(删除
app/cache
文件夹的内容,然后运行app/console缓存:清除
)
您使用的是什么数据库平台?这是symfonyI使用MySQL数据库的更多证据。当我尝试更新时,我得到:property Beachteam\BeachteamBundle\Entity\Item::$type不存在我看到您更新了Item Entity,现在它缺少了“*@ORM\DiscriminatorColumn(name=“type”,type=“string”)`保留注释,但删除变量$type,现在您有两个@ORM\DiscriminatorMap注释。删除一个,我不确定您的类中是否有一个注释。您可以描述出现此错误的时间吗?我已复制粘贴了您的代码,但仍然可以正常工作。可能我错过了您执行的某些行为或操作。另一方面,当我使用doct时rine:schema:validate我能看到的所有@ORM\manytone(targetEntity=“Beachteam\BeachteamBundle\Entity\User”)
缺少inversedBy声明。仅此而已。还有一件事:请发布Symfony和php版本。我正在使用Symfony 2.4.1和php 5.4.20修复我的DiscriminatorMap并删除我的类型变量+getter/setter并验证我得到的架构:Property Beachteam\BeachteamBundle\Entity\Item:$type不存在