<div dir="ltr">2008/7/31 Tom Ward <span dir="ltr"><<a href="mailto:tom@popdog.net">tom@popdog.net</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Thu, Jul 31, 2008 at 5:39 PM, Anthony Green <<a href="mailto:email@acgreen.co.uk">email@acgreen.co.uk</a>> wrote:<br>
><br>
> I thought transactions were usually called within a controller ?<br>
<br>
</div>I don't think so. In almost all circumstances, database transactions<br>
belong in the model.<br>
<div class="Ih2E3d"><br>
> What I'm looking for is a solution defined as part of the association<br>
> declaration thereby enforcing the business rules the objects have.<br>
><br>
> ..or similar<br>
<br>
</div>I think if you do something like:<br>
<br>
b = Book.new(:title => 'Catch 22')<br>
b.author.build(:name => 'Joseph Heller')<br>
b.save<br>
<br>
b.save should save the author and the book, both within a transaction<br>
(so if one fails, they will both fail)<br>
<br>
CAUTION: I've not actually tried this....</blockquote><div><br>Verified.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<font color="#888888"><br>
Tom<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</div></div></blockquote></div><br></div>