4
I’m studying Zend Framework 2 and I’m needing a hand to do an update on two tables that are related. Come on.
I have the table entries with the fields:
id_entrada id_notafiscal
and in the rating table the fields:
id_notafiscal cod_notafiscal
I summarized the amount of fields to facilitate.
I need to update the invoice table and I can even use the query:
UPDATE notafiscal en
INNER JOIN entrada e
ON e.id_notafiscal = en.id_notafiscal
and id_entrada='2014-02-24'
SET cod_notafiscal=1
How to do this using Zend 2?
To facilitate a little more I will post the code I use to make a select
between several tables.
public function find($id)
{
$id = (int)$id;
$sql= $this->tableGateway->select(function (Select $select) use ($id) {
$select->join('enotafiscal','entrada.id_notafiscal=enotafiscal.id_notafiscal','cod_notafiscal','left');
$select->join('fornecedor','entrada.id_fornec=fornecedor.id_fornec','desc_forn','left');
$select->join('produtos','entrada.id_produto=produtos.id_produto','desc_produto','left');
$select->where(array ('id_entrada' => $id));
});
$row =$sql->current();
if (!$row){
throw new \Exception("Não foi encontrado entrada com o id = {$id}");
}
return $row;
}
It is possible to do such a thing using Zend’s Tablegateway class?
Some feedback?
– Kenny Rafael
Nothing. I’m still trying to figure it out.
– Marcos Xavier
I did a search and read on a Stackoverflow topic that the tablegateway class is for data from a single table. http://stackoverflow.com/questions/18157695/zf2-database-transactions-with-updating-multiple-tables
– Marcos Xavier