[LRUG] Binding the creation of 2+ objects together

Matthew Rudy Jacobs matthewrudyjacobs at gmail.com
Thu Jul 31 09:55:43 PDT 2008


2008/7/31 Tom Ward <tom at popdog.net>

> On Thu, Jul 31, 2008 at 5:39 PM, Anthony Green <email at acgreen.co.uk>
> wrote:
> >
> > I thought transactions were usually called within a controller ?
>
> I don't think so.  In almost all circumstances, database transactions
> belong in the model.
>
> > What I'm looking for is a solution defined as part of the association
> > declaration thereby enforcing the business rules the objects have.
> >
> > ..or similar
>
> I think if you do something like:
>
> b = Book.new(:title => 'Catch 22')
> b.author.build(:name => 'Joseph Heller')
> b.save
>
> b.save should save the author and the book, both within a transaction
> (so if one fails, they will both fail)
>
> CAUTION: I've not actually tried this....


Verified.


>
> Tom
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20080731/dbf1f582/attachment.html>


More information about the Chat mailing list