有什么方法可以在使用 Doctrine 时创建一个像另一个一样的表?我知道在 MySQL 中有一个函数可以这样做:
CREATE TABLE user2 LIKE user;
表 user 和 user2 将是相同的。这可以在 Doctrine 中完成吗?
最佳答案
我想您正在寻找的是定义(让我们使用您的示例)在架构级别 user2
继承自 user
当您的模型生成时。您可以使用 Doctrine 的具体 继承来做到这一点 is described in the documentation .
因此,在您的 schema.yml
中:
User:
columns:
name: string
User2:
inheritance:
extends: User
type: concrete
columns:
something: int
这样 user2
将是一个单独的表,并包含与之前在 user
中定义的相同的列(“名称”)。我不确定您为什么想要两个相同 表,但使用上述方法绝对可以做到这一点。
关于php - Doctrine ORM : Create Table Like Another,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1675185/