我正在尝试将多对一关联添加到供应商包中的现有实体。
这是我在供应商包中的实体:-
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 并尝试了其他继承方法。但是他们都没有为只是将关联添加到“Post”实体而工作。
我只想拥有如下内容(尝试将其添加到 orm 映射文件中但不起作用):-
manyToOne:
user:
targetEntity: TP\Bundle\MainBundle\Entity\User
joinColumns:
user_id:
referencedColumnName: id
最佳答案
作为解决方案,我可以建议 SonataEasyExtendsBundle .作为docs说,它解决的问题之一是:
If a developer wants to add a new property into a VB entity, the developer needs to create a new child entity with a custom mapping.
但它有一些requirements对于供应商 bundle 。您可以阅读短文 explanation并决定它是否适合您。
关于php - 使用 yml 配置向现有供应商包实体添加新字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25780556/