respond_to do |format|
if @entity.save && @client.save
This works, to a point. My problem is that when a validation error is
thrown in the client role the entity is created nonetheless. Thus, when
the validation error is corrected then the error then becomes that the
entity is already on file. So, what is the correct idiom for handling
this in create action? Do I do a trial save on the dependent model
first?
True, but it's nice to get the model to do the work. Also you'd have a
bit of race condition (for instance, if someone else saved a record
with a unique field that was the same as one of yours) -- though I'm
not at all sure that validates_associated would solve that part of it
either.
In this particular case, the uniqueness attribute is enforced at the
DBMS level via a unique index on entity_id in clients and on entity_name
in entities. The validates_associated in both models notwithstanding.
Entity_name is normalized to a lowercase sting with all leading,
trailing, and excess whitespace removed.