Skip to content

Instantly share code, notes, and snippets.

@matej21
Last active August 29, 2015 14:06
Show Gist options
  • Save matej21/327f2815a782d5d422a9 to your computer and use it in GitHub Desktop.
Save matej21/327f2815a782d5d422a9 to your computer and use it in GitHub Desktop.
Prefixovane tabulky
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_)
<?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);
}
}
<?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