<?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>Kickass Labs &#187; sqlite</title>
	<atom:link href="http://www.kickasslabs.com/tag/sqlite/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kickasslabs.com</link>
	<description>We &#9829; code.</description>
	<lastBuildDate>Wed, 28 Dec 2011 16:57:56 +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>Don&#8217;t try to be smarter than ActiveRecord</title>
		<link>http://www.kickasslabs.com/2008/11/17/dont-try-to-be-smarter-than-activerecord/</link>
		<comments>http://www.kickasslabs.com/2008/11/17/dont-try-to-be-smarter-than-activerecord/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 15:52:20 +0000</pubDate>
		<dc:creator>gabe</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sanitization]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.kickasslabs.com/?p=81</guid>
		<description><![CDATA[When you&#8217;re writing conditions for a finder in ActiveRecord, and you want to use an array of values for a sql in() statement, you might think to help ActiveRecord out and comma-separate the array values like this: type_ids = [1, &#8230; <a href="http://www.kickasslabs.com/2008/11/17/dont-try-to-be-smarter-than-activerecord/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re writing conditions for a finder in ActiveRecord, and you want to use an array of values for a sql in() statement, you might think to help ActiveRecord out and comma-separate the array values like this:</p>
<pre><code>type_ids = [1, 2, 3]
Something.find(
  :all,
  :conditions =&gt; ['type_id in (?)', type_ids.join(',') ] )
</code></pre>
<p>Which will generate a sql fragment that looks like this:</p>
<blockquote><p>[...] where events.status_id in (&#8217;1,2,3&#8242;) [...]</p></blockquote>
<p>Well, this will work just fine if you&#8217;re using MySQL, but not so fine (read &#8216;at all&#8217;) if you&#8217;re using SQLite.  So, if you&#8217;re using MySQL for your development environment and SQLite for your test environment, like me, it will work fine in dev and fail in your tests.</p>
<p>So, instead, just let ActiveRecord&#8217;s sanitizers do their job and write:</p>
<pre><code>Something.find(
  :all,
  :conditions =&gt; ['type_id in (?)', type_ids])</code></pre>
<p>Your sanity will thank you.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.kickasslabs.com%2F2008%2F11%2F17%2Fdont-try-to-be-smarter-than-activerecord%2F&amp;title=Don%26%238217%3Bt%20try%20to%20be%20smarter%20than%20ActiveRecord" id="wpa2a_2"><img src="http://www.kickasslabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.kickasslabs.com/2008/11/17/dont-try-to-be-smarter-than-activerecord/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

