Use mysql view with cakephp

0

Hello. I look for expenses according to certain parameters and display the results in the cakephp view. But when I delete an expense, I have to search again. How do I resolve this without having to search every time I delete a result? Would a view, temp table, or trigger help me? I have the following query:

$despesas=$this->Despesa->afterFind($this->Despesa->query(
"select despesas.id_despesa, despesas.despesa, despesas.valor_despesa, despesas.data_despesa, despesas.local_despesa, tipos.tipo
from despesas inner join tipos
on despesas.fk_id_tipo=tipos.id_tipo
inner join users
on (users.id=despesas.fk_id_user)
where year(data_despesa)='{$this->request->data['Despesa']['ano']}' and month(data_despesa)='{$this->request->data['Despesa']['mes']}'
and users.id='{$this->request->data['Despesa']['id_user']}'"));

I want to use a view because when I delete the expense the others will still be displayed on the cakephp view.

For example:

create view vw_despesas
as
    select despesas.id_despesa, despesas.despesa, despesas.valor_despesa, despesas.data_despesa, despesas.local_despesa, tipos.tipo
    from despesas inner join tipos
    on despesas.fk_id_tipo=tipos.id_tipo
    inner join users
    on (users.id=despesas.fk_id_user)
    where year(data_despesa)='{$this->request->data['Despesa']['ano']}' and month(data_despesa)='{$this->request->data['Despesa']['mes']}'
    and users.id='{$this->request->data['Despesa']['id_user']}'));

How do I resolve this? If views do not accept parameters, a temporary table would help me nissso?

    
asked by anonymous 16.12.2018 / 00:55

0 answers