0
I need to make a query for a report more or less like this:
Produto.include(:clientes).where('count(produto.id) < cliente.quantidade')
In sql would be more or less like this:
SELECT
C.NOME, C.QUANTIDADE, COUNT(P.ID)
FROM PRODUTOS AS P
LEFT JOIN CLIENTES AS C ON P.CLIENTE_ID = C.ID
WHERE COUNT(P.ID) < C.QUANTIDADE
How to do this using the Active Record?
I couldn’t make it work on Rails 4. I think this way only in previous versions. Thank you.
– Daniel