Codeigniter - Doctrine插入错误 - 多对一关系 [英] Codeigniter - Doctrine inserting error - Many To One relation

查看:177
本文介绍了Codeigniter - Doctrine插入错误 - 多对一关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,使用Doctrine 2和Codeigniter 2在数据库中插入一个新行。



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


$ b

TABLE:CATEGORIES:



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



$ b

TABLE:LANGUAGES:



id,title,slug,icon



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



ENTITIES:



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

错误: p>

 致命错误:未捕获异常InvalidArgumentException与
消息'通过关系模型找到一个新实体
\Categories#languages'未配置为级联对entity:@持久化
操作。显式持久化新实体或
配置级联持久化操作对关系....

我做错了什么?

解决方案

我已经解决了这个问题。



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


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?

解决方案

I've solved the problem.

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

这篇关于Codeigniter - Doctrine插入错误 - 多对一关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆