error on geting last insert id of db

alnux
Member | 139
+
0
-

hi, first of all it the next script was working good, but i dont know why it stopped working

$cabecera_venta['monto_total'] = $total;
$cabecera_venta['total_cobrado'] = (float)$values['totalcobrado'];
$cabecera_venta['bonos_x_compra'] = $cliente->bonos_x_compra;
$cabecera_venta['precio_especial_x_producto'] = $cliente->precio_especial_x_producto;
$cabecera_venta['actualizado_en'] = $fechahora;

$cab_venta = $this->presenter->model('CabeceraVentaEmpresa')->add($cabecera_venta);
var_dump($cab_venta->id);

but it report me the next notice, on var_dump() line

by the way add method is

public function add($values)
    {
        return $this->context->table($this->table)->insert($values);
    }

Notice

Trying to get property of non-object


my nette version is 2.3.10

Last edited by alnux (2017-12-07 21:04)

Mortisson
Member | 21
+
0
-

Try dumping $cab_venta variable, it is possible that add() method does not return anything, or it returns array and not object

Last edited by Mortisson (2017-12-07 17:33)

alnux
Member | 139
+
0
-

Mortisson wrote:

Try dumping $cab_venta variable, it is possible that add() method does not return anything, or it returns array and not object

it its returnning an array, but without id field. i dont know why??. why by itself change from object to array??? and now it does not working!!!!!!

Last edited by alnux (2017-12-07 17:55)

nightfish
Member | 468
+
0
-

alnux wrote:
it its returnning an array, but without id field. i dont know why??. why by itself change from object to array??? and now it does not working!!!!!!

We cannot be sure, unless you share your add() method with us.

alnux
Member | 139
+
0
-

nightfish wrote:

alnux wrote:
it its returnning an array, but without id field. i dont know why??. why by itself change from object to array??? and now it does not working!!!!!!

We cannot be sure, unless you share your add() method with us.

here you are

 $this->context = $container->getService('database.default.context');



public function add($values)
    {
        return $this->context->table($this->table)->insert($values);
    }

Last edited by alnux (2017-12-07 21:21)

nightfish
Member | 468
+
0
-

Does your table have a primary key?

From the documentation: @return IRow|int|bool Returns IRow or number of affected rows for Selection or table without primary key

Anyway it should return either object (implementing IRow), int or bool… not an array.

alnux
Member | 139
+
0
-

nightfish wrote:

Does your table have a primary key?

From the documentation: @return IRow|int|bool Returns IRow or number of affected rows for Selection or table without primary key

Anyway it should return either object (implementing IRow), int or bool… not an array.

yes all was good, that happened by an hour, but i dont know why now it is working normally. really crazy that becouse i didnt change anything

namphan1998
Member | 3
+
0
-

Thank you so much for the post.
It's really helpful.