php - Doctrine 1.2 多对多关系的列命名约定

标签 php mysql orm doctrine

我正在使用现有的数据库模式,并尝试设置两个具有多对多关系的 Doctrine 模型,as described in this document

当从头开始创建表时,我可以毫不费力地使其工作。但是,现有的联接表使用与 Doctrine 文档中描述的不同的命名约定。具体

Table 1
--------------------------------------------------
table_1_id
....other columns....

Table 2
--------------------------------------------------
table_2_id
....other columns....

Join Table
--------------------------------------------------
fktable1_id
fktable_2_id

基本上,以前的开发人员都在所有外键前面加上 fk

从我看到的示例和一些简短的代码实验来看,Doctrine 1.2 要求连接表使用与其连接的表相同的列名

  1. Is my assumption correct?

  2. If so, has the situation changed in Doctrine 2?

  3. If the answers to either of the above are true, how do you configure the models so that all the columns "line up"

最佳答案

看看at the docs关于 N:M 关系。

当你看

$this->hasColumn('user_id', 'integer', null, array(
                'primary' => true
            )
        );

从文档中,您会发现这取决于您如何在连接模型中命名列。

既然您已有数据库,为什么不通过 Doctrine 生成模型API向您显示所需的选项。我自己用过它并且效果非常好。有时,如果您的结构很复杂,您可能需要进行一些清理,但生成的文件是一个非常好的开始。

关于php - Doctrine 1.2 多对多关系的列命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3063919/

相关文章:

sql - 预加载与连接获取相同吗?

javascript - 我正在从 javascript 传递表单数据中的 JSON。并在 php 中访问该 JSON。它将 ""替换为“

PHP 高性能搜索文本中的给定用户名

java - Liferay Service Builder - 创建引用

mysql - Rails 3 - ActiveRecord 和反向排序

mysql - Sequelize findAll 不是一个函数

sql - Laravel总和 Eloquent 集合

php - Facebook iOS 更新 : integrated the conversions APIs with native php

php - 在 laravel 5.6 中迁移时如何检查 mongo 集合是否存在?

python - 带有 bool 字段的 Django 查询注释