<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - Autosave broken in 2.3.4?]]></title>
		<link>http://railsforum.com/viewtopic.php?id=36725</link>
		<description><![CDATA[The most recent posts in Autosave broken in 2.3.4?.]]></description>
		<lastBuildDate>Thu, 28 Jan 2010 21:49:14 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Autosave broken in 2.3.4?]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=117538#p117538</link>
			<description><![CDATA[<p>bump...anyone?</p>]]></description>
			<author><![CDATA[dummy@example.com (mrjake2)]]></author>
			<pubDate>Thu, 28 Jan 2010 21:49:14 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=117538#p117538</guid>
		</item>
		<item>
			<title><![CDATA[Autosave broken in 2.3.4?]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=116797#p116797</link>
			<description><![CDATA[<p>Hello All,</p><p>Before I post this as a bug to the rails team, I wanted to see if I&#039;m doing something wrong that may be causing this behavior.&nbsp; Specifically, the :autosave property of has_many associations doesn&#039;t seem to be working as per the docs.</p><p>For reference, here is the most current API documentation:<br /><a href="http://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html">http://api.rubyonrails.org/classes/Acti &#133; ation.html</a></p><p>Take a look at the &quot;One-to-many Example&quot; section.&nbsp; I have duplicated the code there exactly in a test application, and it isn&#039;t working for me.&nbsp; Specifically, the parent object is updated, but the child object is not.</p><p>My schema is as follows:</p><p>&nbsp; &nbsp; create_table :posts do |t|<br />&nbsp; &nbsp; &nbsp; t.string :title</p><p>&nbsp; &nbsp; &nbsp; t.timestamps<br />&nbsp; &nbsp; end</p><p>&nbsp; &nbsp; create_table :comments do |t|<br />&nbsp; &nbsp; &nbsp; t.text :body<br />&nbsp; &nbsp; &nbsp; t.integer :post_id</p><p>&nbsp; &nbsp; &nbsp; t.timestamps</p><p>My models are as follows:</p><p>class Post &lt; ActiveRecord::Base<br />&nbsp; &nbsp; &nbsp; &nbsp; has_many :comments, :autosave =&gt; true<br />end</p><p>class Comment &lt; ActiveRecord::Base<br />&nbsp; &nbsp; &nbsp; &nbsp; belongs_to :post<br />end</p><p>In the console, I run the following commands (the post and comments objects are already in the DB at this point):</p><p>post = Post.find(1)<br />post.title # =&gt; &quot;The current global position of migrating ducks&quot;<br />post.comments.first.body # =&gt; &quot;Wow, awesome info thanks!&quot;<br />post.comments.last.body # =&gt; &quot;Actually, your article should be named differently.&quot;</p><p>post.title = &quot;On the migration of ducks&quot;</p><p> post.comments.last.body = &quot;Actually, your article should be named differently. [UPDATED]: You are right, thanks.&quot;</p><p>post.save<br />post.reload</p><p>But this is what I get for output:<br />post.title # =&gt; &quot;On the migration of ducks&quot;<br />post.comments.last.body # =&gt; &quot;Actually, your article should be named differently.&quot;</p><p>Further, looking in the logs this is the only update statement I see:</p><p>Post Update (0.6ms)&nbsp; &nbsp;UPDATE &quot;posts&quot; SET &quot;updated_at&quot; = &#039;2010-01-18 23:32:39&#039;, &quot;title&quot; = &#039;On the migration of ducks&#039; WHERE &quot;id&quot; = 1</p><p>So it appears that the save didn&#039;t cascade down to the comments object, which seems clearly broken to me.&nbsp; I have tried this on two different systems running 2.3.4 and the behavior is repeatable.</p><p>Here&#039;s the weird part, though: If I first call &quot;post.comments&quot; before I try to set the value, it works fine!&nbsp; To be exact:<br />post.title = &quot;On the migration of ducks&quot;</p><p>post.comments #Note that this line was not called above<br />post.comments.last.body = &quot;Actually, your article should be named differently. [UPDATED]: You are right, thanks.&quot;</p><p>post.save<br />post.reload</p><p>Now the output gives me the correct results:<br />post.title # =&gt; &quot;On the migration of ducks&quot;<br />post.comments.last.body # =&gt; &quot;Actually, your article should be named differently. [UPDATED]: You are right, thanks.&quot;</p><p>And the logs contain the correct update:<br />&nbsp; Comment Update (0.3ms)&nbsp; &nbsp;UPDATE &quot;comments&quot; SET &quot;updated_at&quot; = &#039;2010-01-18 23:44:43&#039;, &quot;body&quot; = &#039;Actually, your article should be named differently. [UPDATED]: You are right, thanks.&#039; WHERE &quot;id&quot; = 2</p><br /><p>So this really looks broken to me.&nbsp; I&#039;m guessing that it&#039;s a problem with the way that object references are handled, i.e. that once the object is part of an allocated collection it saves fine but does not save when it is pulled as a single object from the database.&nbsp; But before I submit this to the Rails team as a bug I wanted to see if anybody else had run into this issue, or if I&#039;m just doing something completely boneheaded that I&#039;m not seeing because I&#039;ve spent all day on this.</p>]]></description>
			<author><![CDATA[dummy@example.com (mrjake2)]]></author>
			<pubDate>Mon, 18 Jan 2010 23:51:16 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=116797#p116797</guid>
		</item>
	</channel>
</rss>
