Codeigniter - Doctrine插入错误 - 多对一关系

时间:2011-11-02 18:44:47

标签: codeigniter orm doctrine entity relational-database

我在使用Doctrine 2和Codeigniter 2在数据库中插入新行时遇到问题。

我有两个表:语言,类别。

TABLE:CATEGORIES:

id,languages_id,parent_id,title

详细的表格结构 - http://pastebin.com/NhULaasc

表:语言:

id,title,slug,icon

详细的表格结构 - http://pastebin.com/Y6WpzdqF

实体:

Categories.php - http://pastebin.com/HbpKZGBL

Languages.php - http://pastebin.com/vDEd60NP

modelsLanguagesProxy.php - http://pastebin.com/j6zkeR3J

INSERT程序:

$data = $this->input->post(); 
if( is_array($data) && count($data) ) 
{ 
    unset($data['submit']); 
    $add = new models\Categories(); 
    $add->setLanguage($data['language_id']); 
    $add->setParentId($data['parent']); 
    $add->setTitle($data['title']); 
    $this->em->persist($add); 
    $this->em->flush(); 
    if( $add->getId() ) 
    { 
          $this->session->set_flashdata('message','Kategorija je dodana!'); 
          redirect('admin/kategorije'); 
    }else{ 
          $this->session->set_flashdata('message','Kategorija ni dodana!'); 
          redirect('admin/kategorije'); 
    } 
} 

错误:

Fatal error: Uncaught exception 'InvalidArgumentException' with 
message 'A new entity was found through the relationship 'models 
\Categories#languages' that was not configured to cascade persist 
operations for entity: @. Explicitly persist the new entity or 
configure cascading persist operations on the relationship.... 

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。

我的完整解决方案:https://gist.github.com/1338884