Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/windows-phone-8/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Doctrine orm 许多关系问题_Doctrine Orm_Many To Many_Entity Relationship - Fatal编程技术网

Doctrine orm 许多关系问题

Doctrine orm 许多关系问题,doctrine-orm,many-to-many,entity-relationship,Doctrine Orm,Many To Many,Entity Relationship,我试图将条令实体和关系添加到现有的数据库模式中,但遇到了一些问题 我有4张桌子: +-------------+ +-----------+ +-----------------+ +-------------------+ | customers | | acl_roles | | acl_permissions | | acl_customer_role | --------------- ------------- ------------------- ------

我试图将条令实体和关系添加到现有的数据库模式中,但遇到了一些问题

我有4张桌子:

+-------------+  +-----------+  +-----------------+  +-------------------+
| customers   |  | acl_roles |  | acl_permissions |  | acl_customer_role |
---------------  -------------  -------------------  ---------------------
| customer_id |  | id        |  | role_id         |  | customer_id       |
+-------------+  | name      |  | resource_id     |  | acl_role_id       |
                 +------------  | flags           |  +--------------------
                                +------------------
在我的ACL中,客户可以有许多角色,每个角色可以有许多权限。客户/角色的映射通过
acl\u customer\u role
表完成

我目前在处理这段关系时遇到了一些问题。这些是我的实体(为了简洁起见,删除了一些标准注释):

如您所见,在我的客户实体中,我定义了
$roles
。这是一种多人关系,因为许多角色可能属于许多客户。我正在将联接表设置为
acl\u customer\u role
,并指定需要进行联接的列。但是,我得到以下错误:

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'acl_customer_role.aclrole_id' in 'on clause'' in vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:641
Doctrine的查询似乎试图加入到显然不存在的“acl\u customer\u role.aclrole\u id”上

如何正确指定关系

更新:

不知何故,条令似乎在修改我的列名。当我指定
acl\u role\u id
时,原则去掉第一个下划线,并假设列名为
aclrole\u id
(如上面问题中的错误消息所示)。但是,当我添加两个下划线时,例如
acl\uu role\u id
它将所有下划线都保留在那里,并给出几乎相同的错误,除了现在它无法在
acl\uu role\u id
上加入


我几乎不知所措。

我知道这个问题很老,但最近我遇到了同样的错误/问题,我找到了解决办法

默认情况下,条令使用
DefaultNamingStrategy
类生成joinColumn、joinTableName、propertyToColumnName等名称:

...
public function joinColumnName($propertyName)
{
    return $propertyName . '_' . $this->referenceColumnName();
}
这就是为什么在您的案例中会生成
aclrole\u id
列的原因

要更改该行为,您只需在app/config.yml文件中将Doctrine2的命名策略更改为下划线:

doctrine:

    orm:
        # ...
        naming_strategy: doctrine.orm.naming_strategy.underscore
下划线策略

...
public function joinColumnName($propertyName)
{
    return $this->underscore($propertyName) . '_' . $this->referenceColumnName();
}
这将生成:
acl\u角色\u id

您还可以实施自定义命名策略:

注意:这是在版本2.3中引入的

...
public function joinColumnName($propertyName)
{
    return $this->underscore($propertyName) . '_' . $this->referenceColumnName();
}