Welcome Guest, Not a member yet? Register   Sign In
CI / Doctrine saving one to many relationship data problem
#1

[eluser]Masoner[/eluser]
Hi,

Model relationship definition is like this:

Paper:
$this->hasColumn("category_id","integer");
$this->hasColumn("created_by","integer");

$this->hasOne("User as Created_by", array("local"=>"created_by","foreign"=>"id");
$this->hasOne("Paper_category as Category", array("local"=>"category_id","foreign"=>"id");

User:
$this->hasMany("Paper as papers_Modified",array("local"=>"id","foreign"=>"modified_by"));

Category:
$this->hasMany("Paper as Papers",array("local"=>"id","foreign"=>"category_id"));

And the problem is, when i try to save paper, which doesnt have category and/or created_by defined, it gives me this error:

Quote:Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

Saving is ok, if i give category and created_by values.

So, is it so, that when you define relationships in doctrine, the data becomes required, and for the paper to be saved, you NEED to define created_by and category? Or have i defined models wrong? Im new to the CI/Doctrine and i have been following those great "CodeIgniter and Doctrine from scratch" tutorials.
#2

[eluser]Masoner[/eluser]
Got this solved when changed from InnoDB to MyISAM. Didnt know that InnoDB didnt accept empty values for foreign keys.




Theme © iAndrew 2016 - Forum software by © MyBB