Add a SQL Statement to every query

Hi,
im trying to create an application for multiple customers, where data
shouldnt be accessible to others. So ive added a customer_id to every
db-table where it matters.
Question: How can i add a Statement to find and other sql-commands so
i just pull out the ones belong to the customer, without having to
add :customer => customer to every find query? Whats the easiest way?
a before_filter perhaps, or an overwrite of the find methods?
Perhaps Im wrong with my idea anyway :slight_smile:

On Jul 17, 9:34 am, Tom D. [email protected] wrote:

Hi,
im trying to create an application for multiple customers, where data
shouldnt be accessible to others. So ive added a customer_id to every
db-table where it matters.
Question: How can i add a Statement to find and other sql-commands so
i just pull out the ones belong to the customer, without having to
add :customer => customer to every find query? Whats the easiest way?
a before_filter perhaps, or an overwrite of the find methods?

If you setup your associations correctly (ie customer
has_many :things) then you can do

customer.things.find …

Which is a normal find call, but which is scoped to that customer

Fred

On 17 Jul., 11:12, Frederick C. [email protected]
wrote:

If you setup your associations correctly (ie customer
has_many :things) then you can do

customer.things.find …

Which is a normal find call, but which is scoped to that customer

Fred

Perhaps Im wrong with my idea anyway :slight_smile:

Yes, exactly what i want to do, but is there a possibility to remove
the customer at the beginning, so its more DRY?