<?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>TK Studios &#187; doctrine</title>
	<atom:link href="http://www.tkstudios.com/tag/doctrine/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tkstudios.com</link>
	<description>Web Application Design &#38; Development</description>
	<lastBuildDate>Mon, 20 Jun 2011 16:07:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fixing Doctrine&#8217;s Geographical template precision</title>
		<link>http://www.tkstudios.com/2010/04/27/fixing-doctrines-geographical-template-precision/</link>
		<comments>http://www.tkstudios.com/2010/04/27/fixing-doctrines-geographical-template-precision/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 20:41:47 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[doctrine]]></category>

		<guid isPermaLink="false">http://www.tkstudios.com/?p=156</guid>
		<description><![CDATA[(Note that this blog post is about Doctrine 1.2. At the time of this minor update—Nov 16, 2010—I can&#8217;t seem to actually FIND a Geographical behavior in Doctrine 2. So, if you&#8217;re using Doctrine 2, this post probably isn&#8217;t for you. It sucks, I know, this behavior was friggin&#8217; handy.) Doctrine, an ORM library, has [...]]]></description>
			<content:encoded><![CDATA[<p><em>(Note that this blog post is about Doctrine 1.2. At the time of this minor update—Nov 16, 2010—I can&#8217;t seem to actually FIND a Geographical behavior in Doctrine 2. So, if you&#8217;re using Doctrine 2, this post probably isn&#8217;t for you. It sucks, I know, this behavior was friggin&#8217; handy.)</em></p>
<p><a href="http://www.doctrine-project.org">Doctrine</a>, an <acronym title="Object Relational Mapping">ORM</acronym> library, has a convenient little behavior that you can attach to your tables to give them awesome superpowers of geolocation. It&#8217;s the Geographical template, and it resides in Doctrine/Template/Geographical.php. What it does is add two fields to your table: Latitude and Longitude, and extends your model with the ability to discern distances between any two of these locations.</p>
<p>That&#8217;s all well and good, except that as of 1.2.2, Doctrine&#8217;s default precision for a floating point field is <strong>2</strong>. That doesn&#8217;t allow for very accurate geolocation, as it truncates something like &#8220;+33.544622&#8243; down to &#8220;33.54&#8243;. Not good.</p>
<p><span id="more-156"></span></p>
<p>The documentation says absolutely nothing about fixing this behavior. I found a bug listing, but no actual fix. Thus began a long session of guesswork, all futile, and ending in a &#8220;duhhh&#8221; moment and a quick manual trace of the code to determine how the options for templates are handled.</p>
<p>Long story short, I found a fix, and here it is:</p>
<p>YAML version:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">actAs:
  Geographical:
    latitude:
      options:
        scale: 7
    longitude:
      options:
        scale: 7</pre></div></div>

<p>php model version (in your model&#8217;s setUp() function):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$geographical0</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Doctrine_Template_Geographical<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">'latitude'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'scale'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'longitude'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'scale'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">actAs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$geographical0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=Fixing+Doctrine%E2%80%99s+Geographical+template+precision+http%3A%2F%2Fis.gd%2FfkcCgw+%28%40tkstudios%29" title="Post to Twitter"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=Fixing+Doctrine%E2%80%99s+Geographical+template+precision+http%3A%2F%2Fis.gd%2FfkcCgw+%28%40tkstudios%29" title="Post to Twitter">Tweet This Post</a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/04/27/fixing-doctrines-geographical-template-precision/&amp;title=Fixing+Doctrine%E2%80%99s+Geographical+template+precision" title="Post to Digg"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/04/27/fixing-doctrines-geographical-template-precision/&amp;title=Fixing+Doctrine%E2%80%99s+Geographical+template+precision" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/04/27/fixing-doctrines-geographical-template-precision/&amp;title=Fixing+Doctrine%E2%80%99s+Geographical+template+precision" title="Post to Reddit"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/04/27/fixing-doctrines-geographical-template-precision/&amp;title=Fixing+Doctrine%E2%80%99s+Geographical+template+precision" title="Post to Reddit">Post to Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/04/27/fixing-doctrines-geographical-template-precision/&amp;title=Fixing+Doctrine%E2%80%99s+Geographical+template+precision" title="Post to StumbleUpon"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/04/27/fixing-doctrines-geographical-template-precision/&amp;title=Fixing+Doctrine%E2%80%99s+Geographical+template+precision" title="Post to StumbleUpon">Stumble This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.tkstudios.com/2010/04/27/fixing-doctrines-geographical-template-precision/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

