Codeigniter - 学说插入错误 - 多对一关系

发布于 2024-12-13 03:37:45 字数 1909 浏览 0 评论 0 原文

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

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

表格:类别:

id、 languages_id、parent_id、标题

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

表格:语言:

id、标题、slug、图标

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

实体:

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

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

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

插入过程:

$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.... 

我做错了什么?

I am having a problem with inserting a new row in database using Doctrine 2 and Codeigniter 2.

I have two tables: languages, categories.

TABLE: CATEGORIES:

id, languages_id, parent_id, title

Detailed table structure - http://pastebin.com/NhULaasc

TABLE: LANGUAGES:

id, title, slug, icon

Detailed table structure - http://pastebin.com/Y6WpzdqF

ENTITIES:

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

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

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

INSERT PROCEDURE:

$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'); 
    } 
} 

ERROR:

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.... 

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星星的軌跡 2024-12-20 03:37:46

我已经解决了这个问题。

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

I've solved the problem.

My full solution: https://gist.github.com/1338884

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文