I have a question about how to optimize a query, I'm doing it with a select to an active record query. How could I do this in a single SQL query.
Here, for example, is a request. maintenance_service_requests has a Has and belong to many with billing_documents, where billing_documents has a sender_id. What I do is get the maintenance requests that your billing_document does not have yet with a specific sender_id.
So now it works for me, but I know there is some way to do it with activeRecord only.