how to extend nette\database\context? and fix database transactions?

4 years ago

mcmatak
Member | 492
+
0
-

according to this topic

https://forum.nette.org/…ontext-class

i extended nette\database\context, but it doesnt work, i updated config.neon

with these 2 lines

services:
    nette.database.default.context:
        class: System\Database\Context

but now, nette database is not abble to resolve relations like book->author

make query

SELECT * FROM author WHERE id IN (1)

but the table is “authors” without this extension of nette\database\context it worked

where is the problem?

<?php

namespace System\Database;

class Context extends \Nette\Database\Context
{

    /** @var bool */
    protected $hasActiveTransaction = false;





    public function beginTransaction()
    {
        if ($this->hasActiveTransaction) {
            return false;
        }
        else {
            $this->hasActiveTransaction = parent::beginTransaction();
            return $this->hasActiveTransaction;
        }
    }





    public function commit()
    {
        if ($this->hasActiveTransaction) {
            return false;
        }
        else {
            parent::commit();
            $this->hasActiveTransaction = false;
            return true;
        }
    }





    public function rollback()
    {
        if ($this->hasActiveTransaction) {
            return false;
        }
        else {
            parent::rollback();
            $this->hasActiveTransaction = false;
            return true;
        }
    }

}

Last edited by mcmatak (2015-02-09 17:31)

4 years ago

mcmatak
Member | 492
+
0
-

next link about this topic, but also it doesnt work
https://forum.nette.org/…tr-transakce

4 years ago

mcmatak
Member | 492
+
0
-

i am trying to debug databaseextension

https://github.com/…xtension.php#L86

but at this point is DiscoveredReflection created

but Context is created with ConvetionalReflection

i dont understand ?

4 years ago

mcmatak
Member | 492
+
0
-
/**
 * @return System\Database\Context
 */
public function createServiceDatabase__default__context()
{
    $service = new System\Database\Context($this->getService('database.default'), NULL, $this->getService('cacheStorage'));
    return $service;
}

generated nette configuration temp

why the NULL ????

$this->getService(‘database.default’), NULL