Topic: how to apply a given condition to all DB accesses in an application?
I have various model classes that have a data_owner_id field, and EVERY TIME I need to access some data from DB for any of these models I need to impose the condition on the data_owner_id (data_owner_id = @current_user.data_owner_id), so that I don't end up mixing data that belongs to user X with data that belongs to user Y.
Both me and my other rails-newbie developper buddy feel that there should be a more DRY way to do this. After all the application is very intense on database access and we end up coding the exact same condition in many many places.
Is there a way to implement this with some kind of filter or callbacks (on SQL select actions) or maybe some observer classes? Help is really appreciated.
Thanks a bunch.