【问题标题】:Add a new field to the existing vendor bundle entity with yml configuration使用 yml 配置向现有供应商捆绑实体添加新字段
【发布时间】:2014-09-11 06:29:44
【问题描述】:

我正在尝试向供应商捆绑包中的现有实体添加多对一关联。

这是我在供应商捆绑包中的实体:-

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

【问题讨论】:

    标签: php symfony doctrine-orm


    【解决方案1】:

    作为解决方案,我可以建议SonataEasyExtendsBundle。正如docs 所说,它解决的问题之一是:

    如果开发人员想要将新属性添加到 VB 实体中,则 开发者需要使用自定义映射创建一个新的子实体。

    但它有一些requirements 用于供应商捆绑包。您可以阅读简短的explanation 并决定它是否适合您。

    【讨论】:

      猜你喜欢
      • 2017-03-12
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 1970-01-01
      • 2014-12-03
      • 2012-11-20
      • 1970-01-01
      • 2022-07-10
      相关资源
      最近更新 更多