<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: CodeIgniter and Doctrine from scratch Day 6 – Models with Relationships</title>
	<atom:link href="http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships</link>
	<description>PHP, JS, CSS, jQuery, CodeIgniter, Doctrine</description>
	<lastBuildDate>Fri, 03 Feb 2012 14:33:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: CodeIgniter and Doctrine from scratch. &#124; 世界是平的</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-88046</link>
		<dc:creator>CodeIgniter and Doctrine from scratch. &#124; 世界是平的</dc:creator>
		<pubDate>Mon, 30 Jan 2012 17:34:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-88046</guid>
		<description>[...] Day 6: Models with Relationships [...]</description>
		<content:encoded><![CDATA[<p>[...] Day 6: Models with Relationships [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CodeIgniter and Doctrine from scratch. &#124; 世界是平的</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-88041</link>
		<dc:creator>CodeIgniter and Doctrine from scratch. &#124; 世界是平的</dc:creator>
		<pubDate>Mon, 30 Jan 2012 17:33:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-88041</guid>
		<description>[...] Day 6: Models with Relationships [...]</description>
		<content:encoded><![CDATA[<p>[...] Day 6: Models with Relationships [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CodeIgniter and Doctrine from scratch. &#124; 世界是平的</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-88038</link>
		<dc:creator>CodeIgniter and Doctrine from scratch. &#124; 世界是平的</dc:creator>
		<pubDate>Mon, 30 Jan 2012 17:32:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-88038</guid>
		<description>[...] Day 6: Models with Relationships [...]</description>
		<content:encoded><![CDATA[<p>[...] Day 6: Models with Relationships [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CodeIgniter and Doctrine from Scratch &#187; CodeIgniter Resources</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-82471</link>
		<dc:creator>CodeIgniter and Doctrine from Scratch &#187; CodeIgniter Resources</dc:creator>
		<pubDate>Mon, 09 Jan 2012 05:47:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-82471</guid>
		<description>[...] Part 6 introduces models and esp. relationships in depth: http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships Part 7 explains Data Fitures: [...]</description>
		<content:encoded><![CDATA[<p>[...] Part 6 introduces models and esp. relationships in depth: <a href="http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships" rel="nofollow">http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships</a> Part 7 explains Data Fitures: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: women with big butts</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-68984</link>
		<dc:creator>women with big butts</dc:creator>
		<pubDate>Sun, 27 Nov 2011 10:00:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-68984</guid>
		<description>&lt;strong&gt;women with big butts...&lt;/strong&gt;

[...]CodeIgniter and Doctrine from scratch Day 6 – Models with Relationships &#124; PHP and Stuff[...]...</description>
		<content:encoded><![CDATA[<p><strong>women with big butts&#8230;</strong></p>
<p>[...]CodeIgniter and Doctrine from scratch Day 6 – Models with Relationships | PHP and Stuff[...]&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Can&#8217;t create relationship using doctrine+CI &#171; Mi Casa Es Suit Casa</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-59078</link>
		<dc:creator>Can&#8217;t create relationship using doctrine+CI &#171; Mi Casa Es Suit Casa</dc:creator>
		<pubDate>Tue, 11 Oct 2011 02:05:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-59078</guid>
		<description>[...] folder. If you still wondering about the problem, there&#8217;re some people discuss this topic on this post&#8216;s [...]</description>
		<content:encoded><![CDATA[<p>[...] folder. If you still wondering about the problem, there&#8217;re some people discuss this topic on this post&#8216;s [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CodeIgniter and Doctrine &#124; Me and My Self</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-41129</link>
		<dc:creator>CodeIgniter and Doctrine &#124; Me and My Self</dc:creator>
		<pubDate>Thu, 05 May 2011 02:41:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-41129</guid>
		<description>[...] Day 6: Models with Relationships [...]</description>
		<content:encoded><![CDATA[<p>[...] Day 6: Models with Relationships [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Koen</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-27739</link>
		<dc:creator>Koen</dc:creator>
		<pubDate>Sat, 08 Jan 2011 14:19:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-27739</guid>
		<description>Great tut! thanks!
Any plans on doing a tutorial on many-to-many relations, and how to add or remove date in those?
Cheers, Koen</description>
		<content:encoded><![CDATA[<p>Great tut! thanks!<br />
Any plans on doing a tutorial on many-to-many relations, and how to add or remove date in those?<br />
Cheers, Koen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brett</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-27042</link>
		<dc:creator>Brett</dc:creator>
		<pubDate>Sat, 01 Jan 2011 19:08:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-27042</guid>
		<description>How do you create two foreign keys that point to the same primary key in the same model?
For instance, you have a CreatedUserID and ModifiedUserID.

In my setup() function, I have the following:
$this-&gt;hasOne(&#039;User&#039;, array(
	&#039;local&#039; =&gt; &#039;CreatedUserID&#039;,
	&#039;foreign&#039; =&gt; &#039;UserID&#039;
));
$this-&gt;hasOne(&#039;User&#039;, array(
	&#039;local&#039; =&gt; &#039;ModifiedUserID&#039;,
	&#039;foreign&#039; =&gt; &#039;UserID&#039;
));

It only creates a FK for ModifiedUserID or whatever I have as the last one defined.
any help?</description>
		<content:encoded><![CDATA[<p>How do you create two foreign keys that point to the same primary key in the same model?<br />
For instance, you have a CreatedUserID and ModifiedUserID.</p>
<p>In my setup() function, I have the following:<br />
$this-&gt;hasOne(&#8216;User&#8217;, array(<br />
	&#8216;local&#8217; =&gt; &#8216;CreatedUserID&#8217;,<br />
	&#8216;foreign&#8217; =&gt; &#8216;UserID&#8217;<br />
));<br />
$this-&gt;hasOne(&#8216;User&#8217;, array(<br />
	&#8216;local&#8217; =&gt; &#8216;ModifiedUserID&#8217;,<br />
	&#8216;foreign&#8217; =&gt; &#8216;UserID&#8217;<br />
));</p>
<p>It only creates a FK for ModifiedUserID or whatever I have as the last one defined.<br />
any help?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Coutinho</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-19918</link>
		<dc:creator>Ryan Coutinho</dc:creator>
		<pubDate>Tue, 02 Nov 2010 19:32:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-19918</guid>
		<description>Hi all,

I have created 2 classed named:
Account and Numbers
relation between them = 1 to many -&gt; 1 Account has more Numbers.

i have done an entry on both but want to add another number to the existing account. The account id = 3.

What is the best way to do this?

findOneById($id));

		$number = new Number();
		$number-&gt;msisdn = &quot;5970843&quot;;
		$number-&gt;Account = $account;
		$number-&gt;Bal = $bal;
		$number-&gt;save();
	}
}

this code inserts a new number but with NULL for account number which should be 3.

any help?</description>
		<content:encoded><![CDATA[<p>Hi all,</p>
<p>I have created 2 classed named:<br />
Account and Numbers<br />
relation between them = 1 to many -&gt; 1 Account has more Numbers.</p>
<p>i have done an entry on both but want to add another number to the existing account. The account id = 3.</p>
<p>What is the best way to do this?</p>
<p>findOneById($id));</p>
<p>		$number = new Number();<br />
		$number-&gt;msisdn = &#8220;5970843&#8243;;<br />
		$number-&gt;Account = $account;<br />
		$number-&gt;Bal = $bal;<br />
		$number-&gt;save();<br />
	}<br />
}</p>
<p>this code inserts a new number but with NULL for account number which should be 3.</p>
<p>any help?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tomotechi</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-18962</link>
		<dc:creator>tomotechi</dc:creator>
		<pubDate>Sat, 23 Oct 2010 21:53:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-18962</guid>
		<description>my dirty fix:





[code]
// make a new property, override key checks, save.
$p = new Property();
Doctrine_Manager::connection()-&gt;execute(&#039;SET FOREIGN_KEY_CHECKS = 0&#039;);
$p-&gt;save();
				
// now proceed using the saved property object				
				
$pc = $p-&gt;primary_contact;	

// and this becomes possible		
$p-&gt;primary_contact-&gt;property_id	= $p-&gt;id;
				
$p-&gt;save();

[/code]</description>
		<content:encoded><![CDATA[<p>my dirty fix:</p>
<pre class="brush: plain;">
// make a new property, override key checks, save.
$p = new Property();
Doctrine_Manager::connection()-&gt;execute('SET FOREIGN_KEY_CHECKS = 0');
$p-&gt;save();

// now proceed using the saved property object				

$pc = $p-&gt;primary_contact;	

// and this becomes possible
$p-&gt;primary_contact-&gt;property_id	= $p-&gt;id;

$p-&gt;save();
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: tomotechi</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-18961</link>
		<dc:creator>tomotechi</dc:creator>
		<pubDate>Sat, 23 Oct 2010 21:27:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-18961</guid>
		<description>Hi Everyone,

I ran into a little problem today that is somewhat relevant to this thread.  I find myself coming back here for reference material on using Doctrine with Codeigniter - so hopefully what I learned today will help the next person coming along.  This is in regards to saving related records simultaneously with Doctrine.  The example in the reference manual here: 

http://www.doctrine-project.org/projects/orm/1.2/docs/manual/working-with-models/en#dealing-with-relations

provides an example with a User() object that has a one to one relationship with an Email() object.  The manual suggests that the following is possible:

[code]
$email = $user-&gt;Email;
$user-&gt;Email-&gt;address = &#039;jonwage@gmail.com&#039;;
$user-&gt;save();
[/code]

the save() method would then create both the new user record and email record in the database at the same time.  while this is true, i have finally arrived at the conclusion to that if an inverse one-to-one relationship exists, Doctrine fails to create the records.  Here is my example:

a Contact model definition:
[code]
class Contact extends Doctrine_Record {

	public function setTableDefinition() {
		$this-&gt;hasColumn(&#039;name&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;phone&#039;, &#039;string&#039;);	
		$this-&gt;hasColumn(&#039;email&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;is_recipient&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;address1&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;address2&#039;, &#039;string&#039;);	
		$this-&gt;hasColumn(&#039;city&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;state&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;zip&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;username&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;property_id&#039;, &#039;integer&#039;, 4);
		$this-&gt;hasColumn(&#039;contact_type_id&#039;, &#039;integer&#039;, 4);
	}

	public function setUp() {
		$this-&gt;setTableName(&#039;contact&#039;);
		$this-&gt;actAs(&#039;Timestampable&#039;);
		
		
		$this-&gt;hasOne(&#039;property&#039;, array(
			&#039;local&#039; =&gt; &#039;property_id&#039;,
			&#039;foreign&#039; =&gt; &#039;id&#039;
		));
		
		
		$this-&gt;hasOne(&#039;contact_type&#039;, array(
			&#039;local&#039; =&gt; &#039;contact_type_id&#039;,
			&#039;foreign&#039; =&gt; &#039;id&#039;
		));
	
	}
	
}
[/code]

the corresponding Property model:
[code]
class Property extends Doctrine_Record {

	public function setTableDefinition() {
		$this-&gt;hasColumn(&#039;number&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;address1&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;address2&#039;, &#039;string&#039;);	
		$this-&gt;hasColumn(&#039;city&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;state&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;zip&#039;, &#039;string&#039;);
		$this-&gt;hasColumn(&#039;primary_contact_id&#039;, &#039;integer&#039;, 4);
		$this-&gt;hasColumn(&#039;last_modifier_id&#039;, &#039;integer&#039;, 4);
	}

	public function setUp() {
		$this-&gt;setTableName(&#039;property&#039;);
		$this-&gt;actAs(&#039;Timestampable&#039;);
		
		$this-&gt;hasMany(&#039;contact&#039;, array(
			&#039;local&#039; =&gt; &#039;id&#039;,
			&#039;foreign&#039; =&gt; &#039;property_id&#039;
		));
		
		$this-&gt;hasMany(&#039;violation&#039;, array(
			&#039;local&#039; =&gt; &#039;id&#039;,
			&#039;foreign&#039; =&gt; &#039;property_id&#039;
		));
		
		$this-&gt;hasOne(&#039;contact as primary_contact&#039;, array(
			&#039;local&#039; =&gt; &#039;primary_contact_id&#039;,
			&#039;foreign&#039; =&gt; &#039;id&#039;
		));
		
		$this-&gt;hasOne(&#039;user as last_modifier&#039;, array(
			&#039;local&#039; =&gt; &#039;last_modifier_id&#039;,
			&#039;foreign&#039; =&gt; &#039;id&#039;
		));
		
	}
	
}
[/code]

Doctrine fails to insert when I try this:

[code]
$p = new Property();
// leaving out lots here for brevity
				
$pc = $p-&gt;primary_contact;

// continue on like this:
$p-&gt;primary_contact-&gt;name			= $field[&#039;contact_name&#039;];

$p-&gt;save();
[/code]


finally i tried to work around what seemed like a key constraint problem with this:
[code]

...

Doctrine_Manager::connection()-&gt;execute(
&#039;SET FOREIGN_KEY_CHECKS = 0&#039;);

$p-&gt;save();
[/code]

this then DOES create the Property object in the db, with the primary_contact_id field properly set to the new Contact id.  However, on the other side of the relationship - the &#039;property_id&#039; field for the new Contact record is set to &#039;0&#039; - leading me to the conclusion that the inverse one-to-one relationship is causing the problem.  

I have programming around this fairly easily with a subsequent fetch and update of the contact record, but if anyone knows of a solution, or sees some error in my code that is causing this, please do say so : )

thx!</description>
		<content:encoded><![CDATA[<p>Hi Everyone,</p>
<p>I ran into a little problem today that is somewhat relevant to this thread.  I find myself coming back here for reference material on using Doctrine with Codeigniter &#8211; so hopefully what I learned today will help the next person coming along.  This is in regards to saving related records simultaneously with Doctrine.  The example in the reference manual here: </p>
<p><a href="http://www.doctrine-project.org/projects/orm/1.2/docs/manual/working-with-models/en#dealing-with-relations" rel="nofollow">http://www.doctrine-project.org/projects/orm/1.2/docs/manual/working-with-models/en#dealing-with-relations</a></p>
<p>provides an example with a User() object that has a one to one relationship with an Email() object.  The manual suggests that the following is possible:</p>
<pre class="brush: plain;">
$email = $user-&gt;Email;
$user-&gt;Email-&gt;address = 'jonwage@gmail.com';
$user-&gt;save();
</pre>
<p>the save() method would then create both the new user record and email record in the database at the same time.  while this is true, i have finally arrived at the conclusion to that if an inverse one-to-one relationship exists, Doctrine fails to create the records.  Here is my example:</p>
<p>a Contact model definition:</p>
<pre class="brush: plain;">
class Contact extends Doctrine_Record {

	public function setTableDefinition() {
		$this-&gt;hasColumn('name', 'string');
		$this-&gt;hasColumn('phone', 'string');
		$this-&gt;hasColumn('email', 'string');
		$this-&gt;hasColumn('is_recipient', 'string');
		$this-&gt;hasColumn('address1', 'string');
		$this-&gt;hasColumn('address2', 'string');
		$this-&gt;hasColumn('city', 'string');
		$this-&gt;hasColumn('state', 'string');
		$this-&gt;hasColumn('zip', 'string');
		$this-&gt;hasColumn('username', 'string');
		$this-&gt;hasColumn('property_id', 'integer', 4);
		$this-&gt;hasColumn('contact_type_id', 'integer', 4);
	}

	public function setUp() {
		$this-&gt;setTableName('contact');
		$this-&gt;actAs('Timestampable');

		$this-&gt;hasOne('property', array(
			'local' =&gt; 'property_id',
			'foreign' =&gt; 'id'
		));

		$this-&gt;hasOne('contact_type', array(
			'local' =&gt; 'contact_type_id',
			'foreign' =&gt; 'id'
		));

	}

}
</pre>
<p>the corresponding Property model:</p>
<pre class="brush: plain;">
class Property extends Doctrine_Record {

	public function setTableDefinition() {
		$this-&gt;hasColumn('number', 'string');
		$this-&gt;hasColumn('address1', 'string');
		$this-&gt;hasColumn('address2', 'string');
		$this-&gt;hasColumn('city', 'string');
		$this-&gt;hasColumn('state', 'string');
		$this-&gt;hasColumn('zip', 'string');
		$this-&gt;hasColumn('primary_contact_id', 'integer', 4);
		$this-&gt;hasColumn('last_modifier_id', 'integer', 4);
	}

	public function setUp() {
		$this-&gt;setTableName('property');
		$this-&gt;actAs('Timestampable');

		$this-&gt;hasMany('contact', array(
			'local' =&gt; 'id',
			'foreign' =&gt; 'property_id'
		));

		$this-&gt;hasMany('violation', array(
			'local' =&gt; 'id',
			'foreign' =&gt; 'property_id'
		));

		$this-&gt;hasOne('contact as primary_contact', array(
			'local' =&gt; 'primary_contact_id',
			'foreign' =&gt; 'id'
		));

		$this-&gt;hasOne('user as last_modifier', array(
			'local' =&gt; 'last_modifier_id',
			'foreign' =&gt; 'id'
		));

	}

}
</pre>
<p>Doctrine fails to insert when I try this:</p>
<pre class="brush: plain;">
$p = new Property();
// leaving out lots here for brevity

$pc = $p-&gt;primary_contact;

// continue on like this:
$p-&gt;primary_contact-&gt;name			= $field['contact_name'];

$p-&gt;save();
</pre>
<p>finally i tried to work around what seemed like a key constraint problem with this:</p>
<pre class="brush: plain;">

...

Doctrine_Manager::connection()-&gt;execute(
'SET FOREIGN_KEY_CHECKS = 0');

$p-&gt;save();
</pre>
<p>this then DOES create the Property object in the db, with the primary_contact_id field properly set to the new Contact id.  However, on the other side of the relationship &#8211; the &#8216;property_id&#8217; field for the new Contact record is set to &#8217;0&#8242; &#8211; leading me to the conclusion that the inverse one-to-one relationship is causing the problem.  </p>
<p>I have programming around this fairly easily with a subsequent fetch and update of the contact record, but if anyone knows of a solution, or sees some error in my code that is causing this, please do say so : )</p>
<p>thx!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-14683</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Sat, 04 Sep 2010 17:13:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-14683</guid>
		<description>Hi there,
first of all thanks for this great tutorial!
I am having a little trouble with something though... I want to delete a table that I created following this tutorial, because I want to change some parameters in setTableDefinition (stuff like null, notnull, unique, etc.).
But when I try to drop the table I get this error message from PhpMyAdmin:
&quot;Cannot delete or update a parent row: a foreign key constraint fails&quot;

How do I remove the foreign key constraint?</description>
		<content:encoded><![CDATA[<p>Hi there,<br />
first of all thanks for this great tutorial!<br />
I am having a little trouble with something though&#8230; I want to delete a table that I created following this tutorial, because I want to change some parameters in setTableDefinition (stuff like null, notnull, unique, etc.).<br />
But when I try to drop the table I get this error message from PhpMyAdmin:<br />
&#8220;Cannot delete or update a parent row: a foreign key constraint fails&#8221;</p>
<p>How do I remove the foreign key constraint?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Armand van der Walt</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-14465</link>
		<dc:creator>Armand van der Walt</dc:creator>
		<pubDate>Mon, 30 Aug 2010 20:25:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-14465</guid>
		<description>Found the problem, its related to not having assigned something to $post-&gt;Companys</description>
		<content:encoded><![CDATA[<p>Found the problem, its related to not having assigned something to $post-&gt;Companys</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Armand van der Walt</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-14464</link>
		<dc:creator>Armand van der Walt</dc:creator>
		<pubDate>Mon, 30 Aug 2010 20:11:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-14464</guid>
		<description>I have narrowed my problem down to where in the post class I had the relationship with the company.
This is the code that gives me the error:
$this-&gt;hasOne(&#039;Companys&#039;, array(
                &#039;local&#039; =&gt; &#039;companys_id&#039;,
                &#039;foreign&#039; =&gt; &#039;id&#039;
        ));</description>
		<content:encoded><![CDATA[<p>I have narrowed my problem down to where in the post class I had the relationship with the company.<br />
This is the code that gives me the error:<br />
$this-&gt;hasOne(&#8216;Companys&#8217;, array(<br />
                &#8216;local&#8217; =&gt; &#8216;companys_id&#8217;,<br />
                &#8216;foreign&#8217; =&gt; &#8216;id&#8217;<br />
        ));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Armand van der Walt</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-14463</link>
		<dc:creator>Armand van der Walt</dc:creator>
		<pubDate>Mon, 30 Aug 2010 19:55:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-14463</guid>
		<description>Hi

Thanks for great tut.

But unfortunately I have a problem with my relations. I can&#039;t figure what the problem is, and its most likely something stupid that I did. Any help will be great.

Fatal error: Uncaught exception &#039;Doctrine_Connection_Mysql_Exception&#039; with message &#039;SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`ci_doctrine`.`post`, CONSTRAINT `post_companys_id_companys_id` FOREIGN KEY (`companys_id`) REFERENCES `companys` (`id`))&#039; in C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php:1082 Stack trace: #0 C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection\Statement.php(269): Doctrine_Connection-&gt;rethrowException(Object(PDOException), Object(Doctrine_Connection_Statement)) #1 C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php(1042): Doctrine_Connection_Statement-&gt;execute(Array) #2 C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php(687): Doctrine_Connection-&gt;exec(&#039;INSERT INTO pos...&#039;, Array) #3 C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection\UnitOfWork.p in C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php on line 1082

The code:
class Post extends Doctrine_Record {

	public function setTableDefinition() {
		$this-&gt;hasColumn(&#039;content&#039;, &#039;string&#039;, 65535);
		$this-&gt;hasColumn(&#039;category_id&#039;, &#039;integer&#039;, 4);
		$this-&gt;hasColumn(&#039;companys_id&#039;, &#039;integer&#039;, 4);
	}

	public function setUp() {
		$this-&gt;actAs(&#039;Timestampable&#039;);
		$this-&gt;hasOne(&#039;Category&#039;, array(
			&#039;local&#039; =&gt; &#039;category_id&#039;,
			&#039;foreign&#039; =&gt; &#039;id&#039;
		));
		$this-&gt;hasOne(&#039;Companys&#039;, array(
			&#039;local&#039; =&gt; &#039;companys_id&#039;,
			&#039;foreign&#039; =&gt; &#039;id&#039;
		));
	}

}

class Category extends Doctrine_Record {

	public function setTableDefinition() {
		$this-&gt;hasColumn(&#039;title&#039;, &#039;string&#039;, 255);
	}

	public function setUp() {
		$this-&gt;hasMany(&#039;Post as Posts&#039;, array(
			&#039;local&#039; =&gt; &#039;id&#039;,
			&#039;foreign&#039; =&gt; &#039;category_id&#039;
		));
	}
}

class Companys extends Doctrine_Record{
    public function  setTableDefinition() {
        $this-&gt;hasColumn(&#039;companyName&#039;, &#039;string&#039;, 255, array(&#039;unique&#039; =&gt; &#039;true&#039;));
        $this-&gt;hasColumn(&#039;contactPerson&#039;, &#039;string&#039;, 255);
        $this-&gt;hasColumn(&#039;contactNumber&#039;, &#039;string&#039;, 255);
        $this-&gt;hasColumn(&#039;mobileNumber&#039;, &#039;string&#039;, 255);
        $this-&gt;hasColumn(&#039;email&#039;, &#039;string&#039;, 255, array(&#039;unique&#039; =&gt; &#039;true&#039;));
        $this-&gt;hasColumn(&#039;password&#039;, &#039;string&#039;, 255);
        $this-&gt;hasColumn(&#039;category_of&#039;, &#039;string&#039;, 255);
    }

    public function  setUp() {
        $this-&gt;setTableName(&#039;companys&#039;);
        $this-&gt;actAs(&#039;Timestampable&#039;);
        $this-&gt;hasMutator(&#039;password&#039;, &#039;_encrypt_password&#039;);
        $this-&gt;hasMany(&#039;Post as Posts&#039;, array(
			&#039;local&#039; =&gt; &#039;id&#039;,
			&#039;foreign&#039; =&gt; &#039;companys_id&#039;
		));
    }

    protected function _encrypt_password($value)
    {
        $salt = &#039;#*seCret!@-*%&#039;;
        $this-&gt;_set(&#039;password&#039;, md5($salt . $value));
    }
}</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>Thanks for great tut.</p>
<p>But unfortunately I have a problem with my relations. I can&#8217;t figure what the problem is, and its most likely something stupid that I did. Any help will be great.</p>
<p>Fatal error: Uncaught exception &#8216;Doctrine_Connection_Mysql_Exception&#8217; with message &#8216;SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`ci_doctrine`.`post`, CONSTRAINT `post_companys_id_companys_id` FOREIGN KEY (`companys_id`) REFERENCES `companys` (`id`))&#8217; in C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php:1082 Stack trace: #0 C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection\Statement.php(269): Doctrine_Connection-&gt;rethrowException(Object(PDOException), Object(Doctrine_Connection_Statement)) #1 C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php(1042): Doctrine_Connection_Statement-&gt;execute(Array) #2 C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php(687): Doctrine_Connection-&gt;exec(&#8216;INSERT INTO pos&#8230;&#8217;, Array) #3 C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection\UnitOfWork.p in C:\wamp\www\ci_doctrine\system\application\plugins\doctrine\lib\Doctrine\Connection.php on line 1082</p>
<p>The code:<br />
class Post extends Doctrine_Record {</p>
<p>	public function setTableDefinition() {<br />
		$this-&gt;hasColumn(&#8216;content&#8217;, &#8216;string&#8217;, 65535);<br />
		$this-&gt;hasColumn(&#8216;category_id&#8217;, &#8216;integer&#8217;, 4);<br />
		$this-&gt;hasColumn(&#8216;companys_id&#8217;, &#8216;integer&#8217;, 4);<br />
	}</p>
<p>	public function setUp() {<br />
		$this-&gt;actAs(&#8216;Timestampable&#8217;);<br />
		$this-&gt;hasOne(&#8216;Category&#8217;, array(<br />
			&#8216;local&#8217; =&gt; &#8216;category_id&#8217;,<br />
			&#8216;foreign&#8217; =&gt; &#8216;id&#8217;<br />
		));<br />
		$this-&gt;hasOne(&#8216;Companys&#8217;, array(<br />
			&#8216;local&#8217; =&gt; &#8216;companys_id&#8217;,<br />
			&#8216;foreign&#8217; =&gt; &#8216;id&#8217;<br />
		));<br />
	}</p>
<p>}</p>
<p>class Category extends Doctrine_Record {</p>
<p>	public function setTableDefinition() {<br />
		$this-&gt;hasColumn(&#8216;title&#8217;, &#8216;string&#8217;, 255);<br />
	}</p>
<p>	public function setUp() {<br />
		$this-&gt;hasMany(&#8216;Post as Posts&#8217;, array(<br />
			&#8216;local&#8217; =&gt; &#8216;id&#8217;,<br />
			&#8216;foreign&#8217; =&gt; &#8216;category_id&#8217;<br />
		));<br />
	}<br />
}</p>
<p>class Companys extends Doctrine_Record{<br />
    public function  setTableDefinition() {<br />
        $this-&gt;hasColumn(&#8216;companyName&#8217;, &#8216;string&#8217;, 255, array(&#8216;unique&#8217; =&gt; &#8216;true&#8217;));<br />
        $this-&gt;hasColumn(&#8216;contactPerson&#8217;, &#8216;string&#8217;, 255);<br />
        $this-&gt;hasColumn(&#8216;contactNumber&#8217;, &#8216;string&#8217;, 255);<br />
        $this-&gt;hasColumn(&#8216;mobileNumber&#8217;, &#8216;string&#8217;, 255);<br />
        $this-&gt;hasColumn(&#8216;email&#8217;, &#8216;string&#8217;, 255, array(&#8216;unique&#8217; =&gt; &#8216;true&#8217;));<br />
        $this-&gt;hasColumn(&#8216;password&#8217;, &#8216;string&#8217;, 255);<br />
        $this-&gt;hasColumn(&#8216;category_of&#8217;, &#8216;string&#8217;, 255);<br />
    }</p>
<p>    public function  setUp() {<br />
        $this-&gt;setTableName(&#8216;companys&#8217;);<br />
        $this-&gt;actAs(&#8216;Timestampable&#8217;);<br />
        $this-&gt;hasMutator(&#8216;password&#8217;, &#8216;_encrypt_password&#8217;);<br />
        $this-&gt;hasMany(&#8216;Post as Posts&#8217;, array(<br />
			&#8216;local&#8217; =&gt; &#8216;id&#8217;,<br />
			&#8216;foreign&#8217; =&gt; &#8216;companys_id&#8217;<br />
		));<br />
    }</p>
<p>    protected function _encrypt_password($value)<br />
    {<br />
        $salt = &#8216;#*seCret!@-*%&#8217;;<br />
        $this-&gt;_set(&#8216;password&#8217;, md5($salt . $value));<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahmed Tawfik</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-13069</link>
		<dc:creator>Ahmed Tawfik</dc:creator>
		<pubDate>Sun, 15 Aug 2010 07:39:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-13069</guid>
		<description>Thanks Burak , It&#039;s a good information :)</description>
		<content:encoded><![CDATA[<p>Thanks Burak , It&#8217;s a good information <img src='http://www.phpandstuff.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Voigt</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-11795</link>
		<dc:creator>Christian Voigt</dc:creator>
		<pubDate>Fri, 06 Aug 2010 14:40:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-11795</guid>
		<description>If, for example, your local key is &#039;4&#039; and the foreign key is declared as &#039;null&#039;, then you will get that exact error.</description>
		<content:encoded><![CDATA[<p>If, for example, your local key is &#8217;4&#8242; and the foreign key is declared as &#8216;null&#8217;, then you will get that exact error.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cristi</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-9636</link>
		<dc:creator>cristi</dc:creator>
		<pubDate>Thu, 22 Jul 2010 10:39:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-9636</guid>
		<description>guys, i need u help in previous situation, please!</description>
		<content:encoded><![CDATA[<p>guys, i need u help in previous situation, please!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cristi</title>
		<link>http://www.phpandstuff.com/articles/codeigniter-doctrine-day-6-models-relationships/comment-page-1#comment-8740</link>
		<dc:creator>cristi</dc:creator>
		<pubDate>Wed, 14 Jul 2010 20:55:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpandstuff.com/?p=500#comment-8740</guid>
		<description>i&#039;ve tried, but in that situation if i try to add a new user to that group i get a &quot;duplicate entry error&quot;. 

maybe u have a better idea, i just want to have groups with users, and every user to be part of just one group.</description>
		<content:encoded><![CDATA[<p>i&#8217;ve tried, but in that situation if i try to add a new user to that group i get a &#8220;duplicate entry error&#8221;. </p>
<p>maybe u have a better idea, i just want to have groups with users, and every user to be part of just one group.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

