A project has 3 tables : client, invoices, deliveries
The relations are:
client has_many invoices
client has_many deliveries
invoices belongs_to client
deliveries belongs_to client
Both invoices and deliveries model have a date field.
Now I want to find all clients who has at least 1 record either in invoices or deliveries within that month, so that need the distinct clients who have records in invoices or have records in deliveries or even both.
How to find the clients using Rails or even SQL ?
Thanks for help
This would be my first crack at it:
Ideally I would want to use named_scope or custom finder method in the model to handle this:
I am pretty sure this should be pretty close to what you need, but I wouldn’t expect it to work without some modifications for your situation.