You can look at Model.with_scope. Also, I do something similar to what you are talking about. I have a user, that belongs to a company. Then company has_many widgets. Every time I create or access a widget, I do it through the association which adds the condition automatically like:
current_user.company.widgets.find(id) or current_user.company.widgets.find(:conditions => ['widget_name = ?',foo])
The resulting sql for both of the above calls will have "company_id = users_company_id" added where users_company_id is the numerical id of the company.
You can read up on with_scope as it may do better for you, depending on what you are wanting to do:
Hope this helps.
Constantin Gavrilescu wrote: