<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Connecting the dots... &#187; &#8220;multiple one to one relationships&#8221;</title>
	<atom:link href="http://blog.rajatpandit.com/tag/multiple-one-to-one-relationships/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rajatpandit.com</link>
	<description>Thoughts on Web Development, Infrastructure and Application Scalability</description>
	<lastBuildDate>Thu, 29 Dec 2011 13:21:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Doctrine: Multiple One-To-One Relation to same table</title>
		<link>http://blog.rajatpandit.com/2009/12/26/doctrine-multiple-one-to-one-relation-to-same-table/</link>
		<comments>http://blog.rajatpandit.com/2009/12/26/doctrine-multiple-one-to-one-relation-to-same-table/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 23:21:08 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA["multiple one to one relationships"]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[Foreign Key]]></category>
		<category><![CDATA[Normalization]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=430</guid>
		<description><![CDATA[I am currently using sfGuardUser table from the sfDoctrineGuardPlugin to link up to a messages table which stores the user id of sender and receiver. To ensure that the data...]]></description>
			<content:encoded><![CDATA[<p>I am currently using <code>sfGuardUser</code> table from the <code>sfDoctrineGuardPlugin</code> to link up to a <code>messages</code> table which stores the user id of sender and receiver. To ensure that the data schema is properly normalised I need to make sure that both the user id are actually foreign keys to the <code>sfGuardUser</code> table. Here are the schemas to get a better under standing of what I am talking about:</p>
<pre class="brush: bash; title: ; notranslate">
sfGuardUser:
  actAs: [Timestampable]
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    username:
      type: string(128)
      notnull: true
      unique: true
    algorithm:
      type: string(128)
      default: sha1
      notnull: true
    salt: string(128)
    password: string(128)
    is_active:
      type: boolean
      default: 1
    is_super_admin:
      type: boolean
      default: false
    last_login:
      type: timestamp
  indexes:
    is_active_idx:
      fields: [is_active]
  relations:
    groups:
      class: sfGuardGroup
      local: user_id
      foreign: group_id
      refClass: sfGuardUserGroup
      foreignAlias: Users
    permissions:
      class: sfGuardPermission
      local: user_id
      foreign: permission_id
      refClass: sfGuardUserPermission
      foreignAlias: Users

Message:
  actAs:
    Timestampable: ~
  columns:
    user_from_id:                  { type: integer(4), notnull: true }
    user_to_id:                    { type: integer(4), notnull: true }
    date_sent:                     { type: timestamp }
    date_read:                     { type: timestamp }
    alertSent:                     { type: boolean, default: false, notnull: true }
    subject:                       { type: string(255), notnull: true }
    body:                          { type: string(255), notnull: true }
  relations:
    Sent:
      class: sfGuardUser
      local: user_from_id
      foreign: id
      type: one
    Recv:
      class: sfGuardUser
      local: user_to_id
      foreign: id
      type: one
</pre>
<p>A couple of things to remember on how I got it working</p>
<ul>
<li>The name of the relationship has to be unique, if the same one is used the last one will be used</li>
<li>You need to use <code>class</code> property to tell it the name of the Model class to use</li>
<li>Have to 100% ensure that the datatype and <strong>size</strong> are the same otherwise the <code>ALTER...</code> sqls generated won&#8217;t work. I had issues of using <code>integer(4)</code> and <code>integer</code> and it took me 10mins of scratching my head to wonder what was wrong</li>
</ul>
<p>Hope this helps someone with a similar problem.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/12/26/doctrine-multiple-one-to-one-relation-to-same-table/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

