1

我正在尝试将 Code Igniter 与 Doctrine 2 集成。除了我无法保存一个对象的属性外,一切都运行良好。

这是一个引发奇怪错误的小代码片段

$account = $this->em->getRepository('Entities\Account')->findOneById($accountId);

$ofx = new \Entities\FinancialRecord();
$a = $accountCatDao->findByPayeeName("PETROCAN", $account);

ofx->setAccount($account);
$ofx->setAmount($b->getAmount());
$ofx->setDatePosted(new DateTime());
$ofx->setDateUser(new DateTime());
$ofx->setPayeeCity($b->getPayeeCity());
$ofx->setPayeeName($b->getPayeeName());
$ofx->setPayeeState($b->getPayeeState());
$ofx->setTransactionId($b->getTransactionId());
$ofx->setTransactionType($b->getTransactionType());

// FOLLOWING LINE CAUSING THE PROBLEM
$ofx->setCategory($a->getCategory());

$this->em->persist($ofx);
$this->em->flush();

抛出错误

Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'No mapping file found named 'Proxies.__CG__.Entities.Category.dcm.yml' for class 'Proxies\__CG__\Entities\Category'.' in      /Users/yannlaviolette/Sites/finance/application/libraries/Doctrine/ORM/Mapping/MappingException.php on line 68

(!)

Doctrine\ORM\Mapping\MappingException: No mapping file found named 'Proxies.__CG__.Entities.Category.dcm.yml' for class 'Proxies\__CG__\Entities\Category'. in /Users/yannlaviolette/Sites/finance/application/libraries/Doctrine/ORM/Mapping/MappingException.php on line 68

我的映射对象

Entities\FinancialRecord:
   type: entity
   table: finance.financial_record
   fields:
      id:
         id: true
         type: bigint
  nullable: false
  generator:
    strategy: SEQUENCE
transactionId:
  type: string
  length: 255
  fixed: false
  nullable: false
  column: transaction_id
transactionType:
  type: string
  length: 10
  fixed: false
  nullable: false
  column: transaction_type
datePosted:
  type: datetimetz
  nullable: false
  column: date_posted
dateUser:
  type: datetimetz
  nullable: false
  column: date_user
payeeName:
  type: string
  length: 255
  fixed: false
  nullable: false
  column: payee_name
payeeCity:
  type: string
  length: 255
  fixed: false
  nullable: false
  column: payee_city
payeeState:
  type: string
  length: 3
  fixed: false
  nullable: false
  column: payee_state
amount:
  type: decimal
  nullable: false
manyToOne:
   category:
      targetEntity: Entities\Category
      cascade: ["persist", "merge"]
    account:
      targetEntity: Entities\Account
      cascade: ["persist", "merge"]
lifecycleCallbacks: {  }

我真的没有想法。在这个问题上花了 2 天时间。有人可以帮我吗?

4

1 回答 1

0

我在一个项目中有一个 manyToOne 关系。

与您的 yml 文件相比,我看到的唯一区别是我没有将Entities\Category其作为 targetEntity,而只是Category.

我的具体实现示例:

manyToOne:
    Order:
        targetEntity: Order
    Product:
        targetEntity: Product
于 2012-10-31T12:03:36.417 回答