I have the following tables: negociacoes
, negociacao_contatos
and negociacao_status
and the following relationships:
negociacoes hasMany negociacao_contatos
negociacoes belongsTo negociacao_status
In negociacao_status
I have two fields: alerta_usuario
(Y / N) and prazo_alerta
(int).
I need to search COUNT of negociacoes
where its (negociacao.negociacao_status_id)
status is alerta_usuario = "Y"
and negociacao_contatos.created
is greater than prazo_alerta
.
That is, I need to count how many trades there are where the last contact was made more than X days ago. What would be the most correct way to do this search? I have tried several alternatives, none of them successfully.