<bdo id='QBLDJ'></bdo><ul id='QBLDJ'></ul>

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

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

        <tfoot id='QBLDJ'></tfoot>

        使用教义创建一对多的多态关系

        Creating a one to many polymorphic relationship with doctrine(使用教义创建一对多的多态关系)
          <tbody id='cOqXm'></tbody>
      1. <tfoot id='cOqXm'></tfoot>

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

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

                  本文介绍了使用教义创建一对多的多态关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  让我首先概述一下场景.我有一个 Note 对象,可以分配给许多不同的对象

                  Let me start by outlining the scenario. I have a Note object that can be assigned to many different objects

                  • 一本书籍可以有一个或多个注释.
                  • 一个图片可以有一个或多个Note.
                  • 一个地址可以有一个或多个备注.
                  • A Book can have one or moreNotes.
                  • An Image can have one or more Notes.
                  • A Address can have one or more Notes.

                  我设想数据库的样子:

                  id | title           | pages
                  1  | harry potter    | 200
                  2  | game of thrones | 500
                  

                  图片

                  id | full      | thumb
                  2  | image.jpg | image-thumb.jpg
                  

                  地址

                  id | street      | city
                  1  | 123 street  | denver
                  2  | central ave | tampa
                  

                  注意

                  id | object_id | object_type | content      | date
                  1  | 1         | image       | "lovely pic" | 2015-02-10
                  2  | 1         | image       | "red tint"   | 2015-02-30
                  3  | 1         | address     | "invalid"    | 2015-01-05
                  4  | 2         | book        | "boobies"    | 2014-09-06
                  5  | 1         | book        | "prettygood" | 2016-05-05
                  

                  问题是,我如何在 Doctrine 中对此进行建模.我读过的所有内容都是关于没有一对多关系的单表继承.

                  The question is, how do I model this inside of Doctrine. Everything I have read about talks about single table inheritance without a one to many relationship.

                  要注意(不是双关语;),您可能会注意到 note 永远不需要基于与其相关的对象的唯一属性.

                  To note (no pun intended ;), you may notice that note never needs unique attributes based on the object its related to.

                  理想情况下,我可以执行 $address->getNotes() 来返回与 $image->getNotes() 相同类型的 Note 对象.

                  Ideally I can do $address->getNotes() which would return the same type of Note object that $image->getNotes() would return.

                  至少我要解决的问题是避免使用三个不同的表:image_notes、book_notes 和 address_notes.

                  At the very minimum the problem I am trying to solve is to avoid having three different tables: image_notes, book_notes and address_notes.

                  推荐答案

                  这个问题给应用程序带来了不必要的复杂性.仅仅因为笔记具有相同的结构并不意味着它们是相同的实体.在 3NF 中对数据库进行建模时,它们不是同一个实体,因为无法将注释从 Book 移动到 Address.在您的描述中,book 和 book_note 等之间存在明确的父子关系,因此对其进行建模.

                  This question introduces unneccessary complexity into the application. Just because the notes have the same structure does not mean that they are the same entity. When modelling the database in 3NF, they are not the same entity because a note can not be moved from a Book to an Address. In your description there is a definitive parent-child relation between book and book_note, etc so model it as such.

                  更多表对数据库来说不是问题,但不必要的代码复杂性是,正如这个问题所表明的那样.这只是为了聪明而聪明.这就是 ORM 的问题,人们停止进行完全规范化,也没有正确建模数据库.

                  More tables is not a problem for the database but unneccessary code complexity is, as this question demonstrates. It is just being clever for clevers sake. This is the trouble with ORMs, people stop doing full normalization and don't model the database correctly.

                  这篇关于使用教义创建一对多的多态关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <i id='FiR3r'><tr id='FiR3r'><dt id='FiR3r'><q id='FiR3r'><span id='FiR3r'><b id='FiR3r'><form id='FiR3r'><ins id='FiR3r'></ins><ul id='FiR3r'></ul><sub id='FiR3r'></sub></form><legend id='FiR3r'></legend><bdo id='FiR3r'><pre id='FiR3r'><center id='FiR3r'></center></pre></bdo></b><th id='FiR3r'></th></span></q></dt></tr></i><div id='FiR3r'><tfoot id='FiR3r'></tfoot><dl id='FiR3r'><fieldset id='FiR3r'></fieldset></dl></div>
                  <tfoot id='FiR3r'></tfoot>

                        • <bdo id='FiR3r'></bdo><ul id='FiR3r'></ul>
                            <tbody id='FiR3r'></tbody>
                        • <legend id='FiR3r'><style id='FiR3r'><dir id='FiR3r'><q id='FiR3r'></q></dir></style></legend>

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