<?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: PHP Doctrine: Fetching related objects with hasOne relationship or one-to-zero-or-one</title>
	<atom:link href="http://stereointeractive.com/blog/2009/07/16/php-doctrine-fetching-related-objects-with-hasone-relationship-or-one-to-zero-or-one/feed/" rel="self" type="application/rss+xml" />
	<link>http://stereointeractive.com/blog/2009/07/16/php-doctrine-fetching-related-objects-with-hasone-relationship-or-one-to-zero-or-one/</link>
	<description>Development Blog</description>
	<lastBuildDate>Mon, 07 May 2012 20:07:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Scott Meves</title>
		<link>http://stereointeractive.com/blog/2009/07/16/php-doctrine-fetching-related-objects-with-hasone-relationship-or-one-to-zero-or-one/comment-page-1/#comment-689</link>
		<dc:creator>Scott Meves</dc:creator>
		<pubDate>Wed, 27 Jul 2011 08:39:02 +0000</pubDate>
		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=240#comment-689</guid>
		<description>More great information here:

If you ever end up with empty related records, the culprit might be these auto-generated objects that get created with you call certain magic methods on an object. 
&lt;pre&gt;&lt;code lang=&quot;php&quot;&gt;
if ($user-&gt;Email-&gt;exists()) {
    // User has e-mail
} else {
    // User does not have a e-mail
}

$user-&gt;clearRelated(&#039;Email&#039;);
&lt;/code&gt;&lt;/pre&gt;

&quot;Because Doctrine will automatically create a new Email object if the user does not have one, we need to clear that reference so that if we were to call $user-&gt;save() it wouldn&#039;t save a blank Email record for the User.&quot;  - http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models

A better method might be:

&lt;pre&gt;&lt;code lang=&quot;php&quot;&gt;
if ($user-&gt;relatedExists(&#039;Email&#039;)) {
// now we won&#039;t get an empty Email record when we save $user
}
&lt;/code&gt;&lt;/pre&gt;

</description>
		<content:encoded><![CDATA[<p>More great information here:</p>
<p>If you ever end up with empty related records, the culprit might be these auto-generated objects that get created with you call certain magic methods on an object. </p>
<pre><code lang="php">
if ($user->Email->exists()) {
    // User has e-mail
} else {
    // User does not have a e-mail
}

$user->clearRelated('Email');
</code></pre>
<p>&#8220;Because Doctrine will automatically create a new Email object if the user does not have one, we need to clear that reference so that if we were to call $user->save() it wouldn&#8217;t save a blank Email record for the User.&#8221;  &#8211; <a href="http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models" rel="nofollow">http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models</a></p>
<p>A better method might be:</p>
<pre><code lang="php">
if ($user->relatedExists('Email')) {
// now we won't get an empty Email record when we save $user
}
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rich Sage</title>
		<link>http://stereointeractive.com/blog/2009/07/16/php-doctrine-fetching-related-objects-with-hasone-relationship-or-one-to-zero-or-one/comment-page-1/#comment-483</link>
		<dc:creator>Rich Sage</dc:creator>
		<pubDate>Mon, 28 Sep 2009 13:47:26 +0000</pubDate>
		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=240#comment-483</guid>
		<description>Great post - I spent 2 days last week discovering the hard way how this works, having come from a Propel background to Doctrine... and then came across your post today typically!  Cheers :-)</description>
		<content:encoded><![CDATA[<p>Great post &#8211; I spent 2 days last week discovering the hard way how this works, having come from a Propel background to Doctrine&#8230; and then came across your post today typically!  Cheers <img src='http://stereointeractive.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

