<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div><br></div>Actually sorry, I haven't explained this that well.<div><br></div><div>Looking at my original example:</div><div><br></div><div><br></div><div>We have </div><div><br></div><div>person.underpants = boxers<br>person.save</div><div><br></div><div>then we call</div><div><br></div><div>person.underpants.build(:style => 'yfronts')</div><div><br></div><div>this doesn't save the yfronts instance, sure, but it DOES null out the foreign key constraint on the 'boxers' row - thus rendering our customer underpantless untill they commit to wearing the yfronts </div><div><br></div><div>(btw, this isn't the real business domain of the app we're working on)</div><div><br></div><div>So, the problem isn't that the new record gets saved (it doesn't), but that the old one is prematurely removed from the association.</div><div><br></div><div>I realise it's a bit of a corner case, but it seems like an unlikely bit of behavour.</div><div><br></div><div>Thanks for your help, all!</div><div><br></div><div>Cheers</div><div><br></div><div>Tim</div><div><br></div><div><div><div>On 23 Sep 2010, at 14:49, Tim Cowlishaw wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 23 Sep 2010, at 14:47, Mr Jaba wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><ul><li><p>If you wish to assign an object to a <tt><a href="http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_one">has_one</a></tt>
association
without saving it,
</p>
</li></ul><p>
use the <tt>association.build</tt> method (documented below).
</p>
</blockquote><br></div><div>Ok, see - that's what I thought, but it's clearly doing something different for me! Occam's razor says I probably have a callback lying around that I hadn't thought about, that's being too eager about saving things. Will double check!</div><div><br></div><div>Thanks for the help!</div><div><br></div><div>Cheers,</div><div><br></div><div>Tim</div><br></div></blockquote></div><br></div></body></html>