Last active
August 29, 2015 14:06
-
-
Save matej21/327f2815a782d5d422a9 to your computer and use it in GitHub Desktop.
Prefixovane tabulky
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
myReflection: | |
class: DiscoveredReflection | |
arguments: [@nette.database.default] | |
setup: | |
- setPrefix(pfx_) | |
nette.database.default.context: | |
class: Context | |
arguments: [@nette.database.default, @myReflection] | |
setup: | |
- setPrefix(pfx_) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Context extends \Nette\Database\Context | |
{ | |
protected $prefix = ""; | |
public function setPrefix($prefix) | |
{ | |
$this->prefix = $prefix; | |
} | |
public function table($table) | |
{ | |
return parent::table($this->prefix . $table); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DiscoveredReflection extends \Nette\Database\Reflection\DiscoveredReflection | |
{ | |
protected $prefix = ""; | |
public function setPrefix($prefix) | |
{ | |
$this->prefix = $prefix; | |
} | |
public function getHasManyReference($table, $key, $refresh = TRUE) | |
{ | |
return parent::getHasManyReference($table, $refresh ? ($this->prefix . $key) : $key, $refresh); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment