[LRUG] Binding the creation of 2+ objects together
Andrew Stewart
boss at airbladesoftware.com
Thu Jul 31 09:42:55 PDT 2008
On 31 Jul 2008, at 17:04, 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.
You could do:
models = [ @a, @b ]
models.each(&:save) if models.map(&:valid?).all?
Regards,
Andy Stewart
-------
http://airbladesoftware.com
More information about the Chat
mailing list