Could someone tell me how to simplify the following function in my Invoice model? It should return all Invoices related to a particular Client (both connected via a Projects table).
def self.search_by_client_id(client_id)
if client_id
projects = Project.where(:client_id => client_id)
Invoice.where(:project_id => projects)
else
scoped
end
end
I really can’t get my head around this. Thanks for any input!
This seems like the perfect opportunity for a scope!