0

我在 Doctrine 2.2 中使用类表继承模式。我的数据库架构如下:


access_id(主键)
access_type(鉴别列) access_role access_acl access_primary
user_id
( 外键)

Child 1
access_id(外键)
account_id(外键)

Child 2
access_id(外键)
distributor_id(外键)

当我尝试向数据库中插入一个新实体时,父查询看起来不错,但子查询有一个额外的参数。当我转储正在执行的查询时,这就是我所看到的:

INSERT INTO user_access_account (access_id, account_id) VALUES (?, ?)   
array('1'=> 39, '2'=> NULL, '3'=> 3 )

'2' 索引是无关的。'1' => 39, '2' => 3 是正确的参数。

用于执行此查询的代码如下:

$entity = new Entity\UserAccessAccount();
$entity->setAccount($account)
       ->setUser($user)
       ->setAccessRole($accessRole)
       ->setAccessAcl($accessAcl)
       ->setAccessPrimary($accessPrimary);

$em->persist($entity);
$em->flush($entity);
4

1 回答 1

0

事实证明,自动生成的实体映射有一些需要删除的数据。back to的oneToOne定义使 Doctrine 相信有一个额外的参数。现在有道理了!UserAccessAccountUserAccess

正确的:

Entity\UserAccessAccount:
  type: entity
  table: user_access_account
  repositoryClass: Repository\UserAccessAccount
  oneToOne:
    account:
      targetEntity: Entity\Account
      cascade: {  }
      mappedBy: null
      inversedBy: null
      joinColumns:
        account_id:
          referencedColumnName: account_id
      orphanRemoval: false
  lifecycleCallbacks: {  }

不正确:

Entity\UserAccessAccount:
  type: entity
  table: user_access_account
  repositoryClass: Repository\UserAccessAccount
  oneToOne:
    account:
      targetEntity: Entity\Account
      cascade: {  }
      mappedBy: null
      inversedBy: null
      joinColumns:
        account_id:
          referencedColumnName: account_id
      orphanRemoval: false
    userAccess:
      targetEntity: Entity\UserAccess
      cascade: {  }
      mappedBy: null
      inversedBy: null
      joinColumns:
        access_id:
          referencedColumnName: user_access
  lifecycleCallbacks: {  }
于 2012-04-24T22:25:33.767 回答