I'm having some trouble figuring out how to implement the following business logic with nests_one (or with accepts_nested_attributes_for using plain activerecord):
An Order has an Organization. When creating an order, the user can fill out organization attributes, two of which are nickname & email. However, if either nickname or matches an existing organization it should be attached to order, but not edited, which I wish to enforce in the model.
Similarly, the Organization has a Contact, with natural primary key email.
Is there a clean way to build this up with the existing ActiveType api using nests_one, or would I be better off just to use attribute organization_attrs etc. and implement the logic in the AR callbacks?
To sum it up: how do I make nested attributes act as find-or-create rather than find-and-update-or-create?
AT's nested attributes were built to only cover the basic amenities provided by Rails' original nested attributes implementation. The functionality you described will need to be implemented in custom callbacks.
I'm having some trouble figuring out how to implement the following business logic with
nests_one
(or withaccepts_nested_attributes_for
using plain activerecord):An
Order
has anOrganization
. When creating an order, the user can fill out organization attributes, two of which arenickname
&email
. However, if either nickname or matches an existing organization it should be attached to order, but not edited, which I wish to enforce in the model.Similarly, the Organization has a Contact, with natural primary key email.
Is there a clean way to build this up with the existing ActiveType api using
nests_one
, or would I be better off just to useattribute organization_attrs
etc. and implement the logic in the AR callbacks?To sum it up: how do I make nested attributes act as find-or-create rather than find-and-update-or-create?