<?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>dec0der &#187; activerecord</title>
	<atom:link href="http://blog.d27n.com/tags/activerecord/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.d27n.com</link>
	<description>the d27n blog</description>
	<lastBuildDate>Wed, 11 Jan 2012 21:08:00 +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>Rails has_many Time.now gotcha</title>
		<link>http://blog.d27n.com/2009/10/07/rails-has_many-time-now-gotcha/</link>
		<comments>http://blog.d27n.com/2009/10/07/rails-has_many-time-now-gotcha/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 04:46:28 +0000</pubDate>
		<dc:creator>dryan</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[has_many]]></category>

		<guid isPermaLink="false">http://blog.d27n.com/?p=61</guid>
		<description><![CDATA[It&#8217;s one of those face palm moments for me, but don&#8217;t use has_many in your rails models if it&#8217;s time dependent data. In the production environment the Time.now will be the time the environment loads the class, which is only once per server start. Keep in mind your code will work in development and test [...]]]></description>
			<content:encoded><![CDATA[<div class="fblikebutton_button" style="float: right; margin-left: 10px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.d27n.com%2F2009%2F10%2F07%2Frails-has_many-time-now-gotcha%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=recommend&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:26px"></iframe>
		</div>
<p>It&#8217;s one of those face palm moments for me, but don&#8217;t use has_many in your rails models if it&#8217;s time dependent data.  In the production environment the Time.now will be the time the environment loads the class, which is only once per server start.  Keep in mind your code will work in development and test mode. So basically the solution is to move those has_many statements into a function.<br />
<code><br />
has_many :recent_stuff, :conditions =&gt; ["starts_at =?", Time.now]<br />
</code></p>
<p>becomes&#8230;<br />
<code><br />
def recent_stuff<br />
timenow = Time.now<br />
self.find(:all, :conditions =&gt; ["starts_at = ?", timenow])<br />
end<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.d27n.com/2009/10/07/rails-has_many-time-now-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Object Caching 405/405 objects using memcached

Served from: blog.d27n.com @ 2012-02-05 12:53:39 -->
