I have a module that I include in several models with this content:
self.class.find_by_foo(bar)
Everything was fine until I started using STI. This line should always generate a request
select * from table where foo=bar"
and not
select * from table where foo=bar AND type="Whatever"
Is there an easy way to avoid this?
I mean two solutions. Walk through the class hierarchy until I find the topmost class before ActiveRecord::Baseor run the query manually, for example:
self.class.find_by_sql("select * from #{self.class.table_name} where foo=bar")
I do not like the solution. Is there a better one?
source
share