代码点火器的学说 - 无法保存ManyToOne

时间:2012-09-21 04:11:46

标签: php codeigniter doctrine

我正在尝试将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天时间解决了这个问题。有人可以帮我PLZ!

1 个答案:

答案 0 :(得分:0)

我在一个项目中有很多关系。

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

具体实施示例:

manyToOne:
    Order:
        targetEntity: Order
    Product:
        targetEntity: Product