Open yarmand opened 9 years ago
Hi! Thanks for submitting this. I can see the benefits, but I can see a fundamental flaw in the implementation. Given that CouchDB does not support transactions, you are opening the floodgates to data inconsistencies by attempting to auto-save the other documents.
In my opinion, all CouchRest Model operations should be atomic, and not have cascading callbacks in order to maintain predictability.
However, I like your refactoring of the "association" parts. If you'd like to submit a pull request with a set of changes to the association handling so that you can turn your changes into another gem, more than happy to add them. A gem called something like couchrest_model_association_saving
would work.
when two models are referencing each other as associations, affecting one model association attribute will also assign the corresponding attribute in the referenced model. Saving a model will trigger save of associated models.
This reproduce the effect of
ActiveRecord
on relationel databases.belongs_to
andas_many
rely on the same foreign key.*example:
without back assignments:
with back assignments:
reverse association calculation
back assignment is triggered by the presence of the
:reverse_association
option.