我正在尝试向供应商捆绑包中的现有实体添加多对一关联。
这是我在供应商捆绑包中的实体:-
class Post
{
private $id;
private $title;
private $accroche;
private $article;
private $categories;
private $comments;
private $created;
private $updated;
private $publied;
}
这是供应商捆绑包中Post实体的orm映射文件:-
Mv'BlogBundle'Entity'AdminBlog'Post:
type: entity
table: null
repositoryClass: Mv'BlogBundle'Entity'AdminBlog'PostRepository
id:
id:
type: integer
generator:
strategy: AUTO
fields:
title:
type: string
length: 150
accroche:
type: text
article:
type: text
created:
type: datetime
gedmo:
timestampable:
on: create
updated:
type: datetime
gedmo:
timestampable:
on: update
publied:
type: datetime
manyToMany:
categories:
targetEntity: Mv'BlogBundle'Entity'AdminBlog'Category
inversedBy: posts
joinTable:
name: post_category
joinColumns:
post_id:
referencedColumnName: id
onDelete: CASCADE
inverseJoinColumns:
category_id:
referencedColumnName: id
onDelete: RESTRICT
oneToMany:
comments:
targetEntity: Mv'BlogBundle'Entity'AdminBlog'Comment
mappedBy: post
我创建了供应商捆绑包的子捆绑包。我研究了mappedSuperclass,并尝试了其他继承方法。但他们中没有一个只是为"邮政"实体添加了一个关联。
我只想有如下的东西(尝试将其添加到orm映射文件中,但不起作用):-
manyToOne:
user:
targetEntity: TP'Bundle'MainBundle'Entity'User
joinColumns:
user_id:
referencedColumnName: id
作为解决方案,我可以建议使用SonataEasyExtendsBundle。正如医生所说,它解决的问题之一是:
如果开发人员希望将新属性添加到VB实体中开发人员需要创建一个具有自定义映射的新子实体。
但它对供应商捆绑包有一些要求。你可以阅读简短的解释并决定它是否适合你。