Table jako Service a cache
- lucass
- Člen | 89
Zdravim
narazim na jeden docela zasadni problem, ale nevim, jestli je to bug nebo feature. Mam MySQL tabulku gw_adapter a k te jsem si udelal sluzbu
adapters:
factory: @database::table(gw_adapter).
Kdykoliv nad touto sluzbou zavolam napr. select s limitem, limit mi zustava nad touto sluzbou i dal, pri jakemkoliv dalsimu dotazu, jako kdyby se sluzba cachovala. Takze kdyz treba v jednom requestu zavolam nejprve select s limitem a nasledne udelam insert pres stejnou sluzbu, i k insertu se mi vklada limit. Kdyz ale to same provedu pres sluzbu database a pristup k tabulce, funguje to bez problemu. Viz nasledujici (vsechno volano v jednom requestu):
1. prvni volani, v poradku
<?php
$this->getService('database')
->table('gw_adapter')
->where('gw_connection_id', 38);
// vystup OK: SELECT `id`, `gw_handler_id` FROM `gw_adapter` WHERE (`gw_connection_id` = 38)
?>
2. druhe volani, v poradku
<?php
$this->getService('adapters')
->where('gw_connection_id', 38)
->limit(1);
// vystup OK: SELECT `id`, `gw_handler_id` FROM `gw_adapter` WHERE (`gw_connection_id` = 38) LIMIT 1
?>
3. treti volani, chybne – prida LIMIT 1
<?php
$this->getService('adapters')
->where('gw_connection_id', 38);
// vystup KO: SELECT `id`, `gw_handler_id` FROM `gw_adapter` WHERE (`gw_connection_id` = 38) LIMIT 1
?>
4. cvrte volani s limitem, v poradku
<?php
$this->getService('database')
->table('gw_adapter')
->where('gw_connection_id', 38)
->limit(1);
// vystup OK: SELECT `id`, `gw_handler_id` FROM `gw_adapter` WHERE (`gw_connection_id` = 38) LIMIT 1
?>
5. v patem volani pres database nechci limit, v poradku
<?php
$this->getService('database')
->table('gw_adapter')
->where('gw_connection_id', 38);
// vystup OK: SELECT `id`, `gw_handler_id` FROM `gw_adapter` WHERE (`gw_connection_id` = 38)
?>
6. v sestem volani pres sluzbu take nechci limit, ale stejne tam je (pretrvava z druheho volani)
<?php
$this->getService('adapters')
->where('gw_connection_id', 38);
// vystup KO: SELECT `id`, `gw_handler_id` FROM `gw_adapter` WHERE (`gw_connection_id` = 38) LIMIT 1
?>
Aktualne tedy neni mozne pracovat s tabulkami jako se sluzbami. Delam neco spatne?
Nette Framework 2.0.6 pro PHP 5.3 nebo 5.4
Diky za reakce.
Editoval lucass (2. 10. 2012 10:57)