[LRUG] Binding the creation of 2+ objects together

Alex Tomlins alex at tomlins.org.uk
Thu Jul 31 09:09:52 PDT 2008


This strikes me as an ideal case for transactions

http://rails-doc.org/rails/ActiveRecord/Transactions/ClassMethods

then you can use the save! methods, so if one of the models fails to 
save, an exception will be thrown, and the transaction rolled back.

Alex

Anthony Green wrote:
> Has anyone encountered a situation in which the business rules state that a
> object can't be saved unless its twin is saved too ?
>
> I'm seeing this is pattern repeated where an object with a has_one
> relationship to a twin is created but you need to check its twin has created
> as well and that both will save. You can't create one entry in a table
> without a corresponding entry in a different table.
>
> Does anyone know of an extension to the association declaration that
> enforces these kind of rules. A source of creation version of :dependent =>
> :destroy
>
> Tony
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
> !DSPAM:3,4891e28861363702311315!
>
>
>   



More information about the Chat mailing list