i have a method in a model that looks like this:
def self.super_data
self.find(:all,
:select => 'name, type, ref_id, SUM(duration) as duration',
:group => 'name, type, ref_id'
)
end
then I would also like to have a method
def self.filter_by_ref_id(filter_ref_id)
self.select{ |l| l.ref_id == filter_ref_id}
end
so I would like to do model.super_data.filter_by_ref_id(1) or something like that, but it seems like it no longer knows what class it is after the first method, so it can’t call the second. is that right? what can I do instead? is this the best way to filter data in rails? thanks!
edit: if you’re in rails 3
You could define them as scopes:
But I’ve been using rails 3 for quite some time now, and I don’t really remember how chaining scopes works in rails 2…