1. <i id='A7Kxh'><tr id='A7Kxh'><dt id='A7Kxh'><q id='A7Kxh'><span id='A7Kxh'><b id='A7Kxh'><form id='A7Kxh'><ins id='A7Kxh'></ins><ul id='A7Kxh'></ul><sub id='A7Kxh'></sub></form><legend id='A7Kxh'></legend><bdo id='A7Kxh'><pre id='A7Kxh'><center id='A7Kxh'></center></pre></bdo></b><th id='A7Kxh'></th></span></q></dt></tr></i><div id='A7Kxh'><tfoot id='A7Kxh'></tfoot><dl id='A7Kxh'><fieldset id='A7Kxh'></fieldset></dl></div>

        <small id='A7Kxh'></small><noframes id='A7Kxh'>

        <tfoot id='A7Kxh'></tfoot>

        <legend id='A7Kxh'><style id='A7Kxh'><dir id='A7Kxh'><q id='A7Kxh'></q></dir></style></legend>
          <bdo id='A7Kxh'></bdo><ul id='A7Kxh'></ul>

        多对一关联映射到 Doctrine 2 中的类表继承实体

        时间:2024-08-15
      2. <i id='4Ma9a'><tr id='4Ma9a'><dt id='4Ma9a'><q id='4Ma9a'><span id='4Ma9a'><b id='4Ma9a'><form id='4Ma9a'><ins id='4Ma9a'></ins><ul id='4Ma9a'></ul><sub id='4Ma9a'></sub></form><legend id='4Ma9a'></legend><bdo id='4Ma9a'><pre id='4Ma9a'><center id='4Ma9a'></center></pre></bdo></b><th id='4Ma9a'></th></span></q></dt></tr></i><div id='4Ma9a'><tfoot id='4Ma9a'></tfoot><dl id='4Ma9a'><fieldset id='4Ma9a'></fieldset></dl></div>

        <small id='4Ma9a'></small><noframes id='4Ma9a'>

            <bdo id='4Ma9a'></bdo><ul id='4Ma9a'></ul>
            <tfoot id='4Ma9a'></tfoot><legend id='4Ma9a'><style id='4Ma9a'><dir id='4Ma9a'><q id='4Ma9a'></q></dir></style></legend>

                  <tbody id='4Ma9a'></tbody>

                • 本文介绍了多对一关联映射到 Doctrine 2 中的类表继承实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 Author 实体,它是一个包含 AuthorUser 和一个 AuthorGroup 的类表继承.

                  I have an Author entity, which is a Class Table Inheritance containing an AuthorUser and an AuthorGroup.

                  /**
                   * Author
                   *
                   * @ORMTable
                   * @ORMEntity
                   * @ORMInheritanceType("JOINED")
                   * @ORMDiscriminatorColumn(name="type", type="string")
                   * @ORMDiscriminatorMap({"user" = "AuthorUser", "group" = "AuthorGroup"})
                   */
                  class Author {
                      // ...
                  }
                  

                  AuthorUser 与我的 User 实体相关,AuthorGroup 与我的 Group 实体相关.

                  AuthorUser relates to my User entity and AuthorGroup to my Group entity.

                  class AuthorUser extends Author
                  {
                      /**
                       * @var User
                       *
                       * @ORMManyToOne(targetEntity="User", inversedBy="?????")
                       * @ORMJoinColumn(name="user_id", referencedColumnName="id")
                       */
                      protected $user;
                  }
                  
                  class AuthorGroup extends Author
                  {
                      /**
                       * @var Group
                       *
                       * @ORMManyToOne(targetEntity="Group", inversedBy="?????")
                       * @ORMJoinColumn(name="group_id", referencedColumnName="id")
                       */
                      protected $user;
                  }
                  

                  我不知道如何反转这个.无论如何,问题是我必须将此 CTI 添加到我的 Article 实体字段中.我如何使用 ManyToOne 与这篇文章实体字段相关联?

                  I have no idea how to inverse this. Anyway, the problem is that i have to add this CTI to my Article entity field. How can i relate using ManyToOne to this Article entity field?

                  class Article
                  {
                      /**
                       * @var Author
                       *
                       * @ORMManyToOne(targetEntity="Author", inversedBy="?????????")
                       * @ORMJoinColumn(name="author_id", referencedColumnName="id")
                       */
                      protected $author;
                  }
                  

                  我不确定如何使其尽可能透明.当我创建一个新的 Article 时,我需要向 author 字段提供一个 UserGroup 对象.我遵循了这种行为,但似乎没有帮助.它变得更加复杂.

                  I'm not sure how to make this as transparent as possible. When i create a new Article, i need to provide either an User or Group object to the author field. I followed this behavior, but it doesn't seem to help. It gets even more complicated.

                  推荐答案

                  一种解决方案是始终拥有 AuthorGroups,即使只有一个作者.

                  One solution could be to always have AuthorGroups, even when there's only one Author.

                  否则,看看 https://github.com/FabienPennequin/DoctrineExtensions-Rateable

                  您也许可以使用该代码来提供类似的 Authored 接口,该接口可以区分 AuthorUser 和 AuthorGroup.

                  You might be able to use that code to provide a similar Authored interface that can discriminate between the AuthorUser and AuthorGroup.

                  这篇关于多对一关联映射到 Doctrine 2 中的类表继承实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:教义映射字段不起作用 下一篇:在 Doctrine 中使用 Haversine 进行 SQL 搜索

                  相关文章

                • <small id='9rTSt'></small><noframes id='9rTSt'>

                  <i id='9rTSt'><tr id='9rTSt'><dt id='9rTSt'><q id='9rTSt'><span id='9rTSt'><b id='9rTSt'><form id='9rTSt'><ins id='9rTSt'></ins><ul id='9rTSt'></ul><sub id='9rTSt'></sub></form><legend id='9rTSt'></legend><bdo id='9rTSt'><pre id='9rTSt'><center id='9rTSt'></center></pre></bdo></b><th id='9rTSt'></th></span></q></dt></tr></i><div id='9rTSt'><tfoot id='9rTSt'></tfoot><dl id='9rTSt'><fieldset id='9rTSt'></fieldset></dl></div>

                    • <bdo id='9rTSt'></bdo><ul id='9rTSt'></ul>

                    <tfoot id='9rTSt'></tfoot>
                      <legend id='9rTSt'><style id='9rTSt'><dir id='9rTSt'><q id='9rTSt'></q></dir></style></legend>