原则 2:如何处理带有额外列的连接表 [英] Doctrine 2: How to handle join tables with extra columns

查看:14
本文介绍了原则 2:如何处理带有额外列的连接表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Doctrine 2 中设置带有额外列或多对多关联的连接表?

How do I setup a join table with extra columns, or a many-to-many association with additional properties, in Doctrine 2?

推荐答案

首先,让我解释一下,这存在:

First off, let me explain that this does not exist:

join table(也称为 junction tablecross-reference table)是链接 2 个(或更多)的表格同一个数据库中的其他表通过主键放在一起.这意味着连接表将只包含外键,这些额外的列没有位置.

A join table (also known as a junction table or cross-reference table) is a table that links 2 (or more) other tables together within the same database by primary key. This means that a join table will only contain foreign keys, there is no place for these extra columns.

所以当你需要在这样的表中添加额外的列时,它不再只是一个链接";在其他表之间,但自己成为真正的表

So when you need extra columns in such a table, it is no longer just a "link" between other tables, but becomes a real table on its own!

就 Doctrine 2 而言,您不再拥有 2 个实体之间的多对多关联,而是获得 3 个实体之间的一对多/多对一关联.

In terms of Doctrine 2, you no longer have a many-to-many association between 2 entities, but get a one-to-many/many-to-one association between 3 entities.

继续阅读此处以获得更详细的解释:

Continue reading here for more detailed explanations:

这篇关于原则 2:如何处理带有额外列的连接表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆