Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用条令的通用实体模型_Php_Mysql_Symfony_Doctrine Orm - Fatal编程技术网

Php 使用条令的通用实体模型

Php 使用条令的通用实体模型,php,mysql,symfony,doctrine-orm,Php,Mysql,Symfony,Doctrine Orm,我正在尝试为不同的页面类型创建通用seo表。例如,页面和产品等将有一般的搜索引擎优化标签,如元瓷砖和描述。因此,我尝试根据下图创建模型 我在Symfony2上用条令做这件事。问题是我不知道如何正确地建立与教义的关系 关系 page (id) (One to One)-> Seo type (entity_id) product (id) (One to One)-> Seo type (entity_id) seo entity type (id) (One to Many

我正在尝试为不同的页面类型创建通用seo表。例如,页面和产品等将有一般的搜索引擎优化标签,如元瓷砖和描述。因此,我尝试根据下图创建模型

我在Symfony2上用条令做这件事。问题是我不知道如何正确地建立与教义的关系

关系

page (id) (One to One)-> Seo type (entity_id)  
product (id) (One to One)-> Seo type (entity_id) 

seo entity type (id) (One to Many)-> Seo type (entity_type) 
seo (seo_entity) (One to One)-> Seo type (entity_type_id)
如果有人能指导我,我该怎么做呢。我还有一个问题是Seo实体类型表真的需要。那张桌子还有什么要剥掉的吗

对于上面的关系,我创建了下面的注释。但这是一个错误

class Page
{

/**
 * @ORM\OneToOne(targetEntity="SeoEntity", inversedBy="page")
 * @ORM\JoinColumn(referencedColumnName="entity_id")
 *
 */
protected $entity_id;   

}


class SeoEntity
{

/** @ORM\OneToOne(targetEntity="Page", mappedBy="seoentity", cascade={"persist", "merge"}) */
protected $seo_entity_id;   

/** @ORM\OneToOne(targetEntity="SeoEntityMeta", mappedBy="seoentity", cascade={"persist", "merge"}) */
protected $seo_entity_meta_id;  

}


class SeoEntityMeta
{
/**
 * @ORM\OneToOne(targetEntity="SeoEntity", inversedBy="seo_entity_meta")
 * @ORM\JoinColumn(referencedColumnName="id")
 *
 */
protected $seo_entity_id;

}
低于误差

[条令\DBAL\DBALException]
执行“ALTER TABLE Page ADD CONSTRAINT”时发生异常 FK_B43819; E377A038C国外KY(seo_实体id_id)参考 seo_实体(实体id)“:
SQLSTATE[HY000]:一般错误:1005无法创建表 “sf.#sql-3be_48”(错误号:150)
[PDO例外]
SQLSTATE[HY000]:一般错误:1005无法创建表 “sf.#sql-3be_48”(错误号:150)


是否需要该表取决于您,至于注释,您应该首先尝试使用文档@弗洛斯库斯:我用我尝试过的注释更新了这个问题。但它不起作用。我可以看出我做错了什么,因为映射的对象和反转的对象都是错误的。建议使用以下命令:
php应用程序/控制台原则:generate:entity--entity=“MyBundle:Page”--format=“annotation”
,将
MyBundle
替换为您的bundle名称。在这之后,您可以看到它是如何生成的,您不需要在属性名称后面加上
\u id
,不过,doctrine会在DB中为您这样做