问题
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?
回答1:
I've solved the problem.
My full solution: https://gist.github.com/1338884
来源:https://stackoverflow.com/questions/7985676/codeigniter-doctrine-inserting-error-many-to-one-relation