<?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"
	>
<channel>
	<title>Comments on: Efficient Updates &#038; Data Import in Rails</title>
	<atom:link href="http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/</link>
	<description>A goal is a dream with a deadline.</description>
	<pubDate>Sat, 30 Aug 2008 00:12:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Eric Methot</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-101101</link>
		<dc:creator>Eric Methot</dc:creator>
		<pubDate>Sun, 20 Jan 2008 11:23:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-101101</guid>
		<description>Hi Ilya, I would really be interested in the results you get on real prod code whenever you get around to it. Thanks in advance, Eric</description>
		<content:encoded><![CDATA[<p>Hi Ilya, I would really be interested in the results you get on real prod code whenever you get around to it. Thanks in advance, Eric</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-100992</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Sat, 12 Jan 2008 19:09:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-100992</guid>
		<description>Michael, believe it or not, that should be it. The steps are: establish connection to database, load your items, import your items. After you execute Item.import, check your database -- all of your records should be residing in there!

Eric, very interesting extension to ActiveRecord. I did a quick pass over your code and it's a pretty neat, Ruby idiom specific, implementation. I'll make sure to test-drive it with some production code in the future.</description>
		<content:encoded><![CDATA[<p>Michael, believe it or not, that should be it. The steps are: establish connection to database, load your items, import your items. After you execute Item.import, check your database &#8212; all of your records should be residing in there!</p>
<p>Eric, very interesting extension to ActiveRecord. I did a quick pass over your code and it&#8217;s a pretty neat, Ruby idiom specific, implementation. I&#8217;ll make sure to test-drive it with some production code in the future.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Methot</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-100977</link>
		<dc:creator>Eric Methot</dc:creator>
		<pubDate>Sat, 12 Jan 2008 09:40:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-100977</guid>
		<description>I put together a small plugin (&lt;a href="http://railsparhasard.ericmethot.com/journal/2008/1/9/multi-statement-query-plugin.html" title="multi-statement-query rails plugin" rel="nofollow"&gt;multi-statement-query&lt;/a&gt;) that allows AR to take advantage of MySQL's ability to handle such queries (with some limitations of course). It could be used as a complement to Zack's extension allowing you to also do selects, updates and other insert statements in one go. I mention it here because this is one of the sites that I have stumbled upon when researching the plugin. 

Cheers</description>
		<content:encoded><![CDATA[<p>I put together a small plugin (<a href="http://railsparhasard.ericmethot.com/journal/2008/1/9/multi-statement-query-plugin.html" title="multi-statement-query rails plugin" rel="nofollow">multi-statement-query</a>) that allows AR to take advantage of MySQL&#8217;s ability to handle such queries (with some limitations of course). It could be used as a complement to Zack&#8217;s extension allowing you to also do selects, updates and other insert statements in one go. I mention it here because this is one of the sites that I have stumbled upon when researching the plugin. </p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Staton</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-100945</link>
		<dc:creator>Michael Staton</dc:creator>
		<pubDate>Thu, 10 Jan 2008 00:25:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-100945</guid>
		<description>Ilya, this all makes sense except for the steps left out for the noobs....  Where do I put this code?  How do I execute it?  

I got a huge file that goes, for example, 
items = [Item.new(data hash), etc. ]
Item.import items

Now what?</description>
		<content:encoded><![CDATA[<p>Ilya, this all makes sense except for the steps left out for the noobs&#8230;.  Where do I put this code?  How do I execute it?  </p>
<p>I got a huge file that goes, for example,<br />
items = [Item.new(data hash), etc. ]<br />
Item.import items</p>
<p>Now what?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-85683</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Tue, 13 Nov 2007 07:43:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-85683</guid>
		<description>Marc, unfortunately your example will require some manual 'muck'. There is no direct way (that I'm aware of), to do a multi-value habtm import aside from running two separate multi-value imports. 

As long as you know the correct mappings between ID's, I would first load the parent table, and then import the children  as a separate query.</description>
		<content:encoded><![CDATA[<p>Marc, unfortunately your example will require some manual &#8216;muck&#8217;. There is no direct way (that I&#8217;m aware of), to do a multi-value habtm import aside from running two separate multi-value imports. </p>
<p>As long as you know the correct mappings between ID&#8217;s, I would first load the parent table, and then import the children  as a separate query.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marc Busch</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-85135</link>
		<dc:creator>Marc Busch</dc:creator>
		<pubDate>Mon, 12 Nov 2007 10:57:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-85135</guid>
		<description>Ilya, nice article. But I have a problem to understand how this can be used with habtm tables, i.e. two tables that are linked with a join table.

Example: 
Parent and Child have a has_and_belongs_to_many relation. How can I utilize ar-extension's import functionality for something like this:

1000.times {
    parent.children.create(:par0 =&#62; "test0", :par1 =&#62; "test1")
}

For every single 'create' there are two(!) INSERTs in the database, one to 'child' and the other to the join table 'chidren_parents'. If I use 'import' as described in your article, the join table will not get updated, right?

Can this be solved somehow?</description>
		<content:encoded><![CDATA[<p>Ilya, nice article. But I have a problem to understand how this can be used with habtm tables, i.e. two tables that are linked with a join table.</p>
<p>Example:<br />
Parent and Child have a has_and_belongs_to_many relation. How can I utilize ar-extension&#8217;s import functionality for something like this:</p>
<p>1000.times {<br />
    parent.children.create(:par0 =&gt; &#8220;test0&#8243;, :par1 =&gt; &#8220;test1&#8243;)<br />
}</p>
<p>For every single &#8216;create&#8217; there are two(!) INSERTs in the database, one to &#8216;child&#8217; and the other to the join table &#8216;chidren_parents&#8217;. If I use &#8216;import&#8217; as described in your article, the join table will not get updated, right?</p>
<p>Can this be solved somehow?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-61831</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Tue, 21 Aug 2007 12:46:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-61831</guid>
		<description>Charlie, you should reverse your relationship to simplify the import. Instead of storing the listing_id in a separate table, add a user_id column to your listings! This way, you can supply the user id at import time, and not worry about keeping the second table consistent.

As for ar-extensions, which version of Rails are you using? It is possible that the core team has folded some of these features into the core - having said that, I haven't come across anything mentioning this before, so I would double check if you have a 'require ar-extensions' in another environment file somewhere.</description>
		<content:encoded><![CDATA[<p>Charlie, you should reverse your relationship to simplify the import. Instead of storing the listing_id in a separate table, add a user_id column to your listings! This way, you can supply the user id at import time, and not worry about keeping the second table consistent.</p>
<p>As for ar-extensions, which version of Rails are you using? It is possible that the core team has folded some of these features into the core - having said that, I haven&#8217;t come across anything mentioning this before, so I would double check if you have a &#8216;require ar-extensions&#8217; in another environment file somewhere.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: charlie caroff</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-61589</link>
		<dc:creator>charlie caroff</dc:creator>
		<pubDate>Mon, 20 Aug 2007 17:25:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-61589</guid>
		<description>Ilya, I have another question for you. I commented out the 'require ar-extensions' from my code, and yet this Listing.import action still works.  I don't understand -- your page here seems to imply that I need ar-extensions to do this kind of importing.  Or do I need ar-extensions just to do some fancier stuff?

Charlie</description>
		<content:encoded><![CDATA[<p>Ilya, I have another question for you. I commented out the &#8216;require ar-extensions&#8217; from my code, and yet this Listing.import action still works.  I don&#8217;t understand &#8212; your page here seems to imply that I need ar-extensions to do this kind of importing.  Or do I need ar-extensions just to do some fancier stuff?</p>
<p>Charlie</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: charlie caroff</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-61506</link>
		<dc:creator>charlie caroff</dc:creator>
		<pubDate>Mon, 20 Aug 2007 04:05:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-61506</guid>
		<description>Yes, my newbieness is glaring.  

I am successfully using  your technique to insert multiple rows into a table called listings, which has a parent table called user_listings.

user_listings has a column called listing_id, and listings has the standard auto_increment id column.  

I am inserting multiple rows with one statement into listings, as you suggest, Listing.import names, values.  Works great, thanks.  Appears to be a huge timesaver over inserting one row at a time.

However, I would like to also insert multiple rows into user_listings at the same time, one row for each insertion into listings.  But I don't know the listing_id until it is automatically created in Listings.  I can't figure out how to do that.  Does that make sense?

Charlie</description>
		<content:encoded><![CDATA[<p>Yes, my newbieness is glaring.  </p>
<p>I am successfully using  your technique to insert multiple rows into a table called listings, which has a parent table called user_listings.</p>
<p>user_listings has a column called listing_id, and listings has the standard auto_increment id column.  </p>
<p>I am inserting multiple rows with one statement into listings, as you suggest, Listing.import names, values.  Works great, thanks.  Appears to be a huge timesaver over inserting one row at a time.</p>
<p>However, I would like to also insert multiple rows into user_listings at the same time, one row for each insertion into listings.  But I don&#8217;t know the listing_id until it is automatically created in Listings.  I can&#8217;t figure out how to do that.  Does that make sense?</p>
<p>Charlie</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2007/07/11/efficient-updates-data-import-in-rails/#comment-61478</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Mon, 20 Aug 2007 01:50:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2007/07/11/efficient-updates-data-import-in-rails/#comment-61478</guid>
		<description>Charlie, I'm not sure in with you on this one. You can't insert into 'joined' tables - a join is just a merged view of the data on some key. You need to update each table individually... or am I misinterpreting your question?</description>
		<content:encoded><![CDATA[<p>Charlie, I&#8217;m not sure in with you on this one. You can&#8217;t insert into &#8216;joined&#8217; tables - a join is just a merged view of the data on some key. You need to update each table individually&#8230; or am I misinterpreting your question?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
