Ruby on Rails Friday, March 28, 2014



On Friday, March 28, 2014 8:47:24 AM UTC-4, Hassan Schroeder wrote:
On Fri, Mar 28, 2014 at 5:00 AM, Walter Lee Davis <wa...@wdstudio.com> wrote:

>> I have an external process changing the database of my app. Is there a good way to trigger the before save and after save filters for models that get updated, when it is an external process changing it?

> Try to think more about your overall application architecture. Maybe your "external process" can call an API in your Rails app instead of changing the database directly, behind its back.

+1 - this scenario has "data integrity fail" stamped all over it.

If you can't avoid having the external process write to the db, at least
have it write to *non-model* tables and incorporate the updates from
there (via periodic rake task, or whatever).

Good luck.
--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

agree with the data integrity concerns.  if it's possible, I think the API solution above is the best option.  It is possible to write a batch invocation of ActiveRecord which your external process would have to call, but I think the cleanest way to insure all the before/after filters are executed is by building an API.  

If you're going to hit the database directly, at least push your model constraints back into the database so that integrity is maintained.  That still potentially leaves an issue with your before/after filters.  For example, if you have an after filter that writes to a log/audit file after a transaction is saved, that won't get executed.  Again, API would be the cleanest and consistent with the way systems interface to each other.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2810ca67-2d99-4b83-9bed-4b11e0a635ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment