Repository: add support for per-table datasources

refs #13034
This commit is contained in:
Alexander A. Klimov 2016-11-03 14:35:18 +01:00
parent 4a791e6204
commit e655699917
2 changed files with 6 additions and 4 deletions

View File

@ -263,11 +263,13 @@ abstract class Repository implements Selectable
} }
/** /**
* Return the datasource being used * Return the datasource being used for the table $table
*
* @param string $table
* *
* @return Selectable * @return Selectable
*/ */
public function getDataSource() public function getDataSource($table = null)
{ {
return $this->ds; return $this->ds;
} }

View File

@ -109,7 +109,7 @@ class RepositoryQuery implements QueryInterface, SortRules, FilterColumns, Itera
*/ */
public function from($target, array $columns = null) public function from($target, array $columns = null)
{ {
$this->query = $this->repository->getDataSource()->select(); $this->query = $this->repository->getDataSource($target)->select();
$this->query->from($this->repository->requireTable($target, $this)); $this->query->from($this->repository->requireTable($target, $this));
$this->query->columns($this->prepareQueryColumns($target, $columns)); $this->query->columns($this->prepareQueryColumns($target, $columns));
$this->target = $target; $this->target = $target;
@ -716,7 +716,7 @@ class RepositoryQuery implements QueryInterface, SortRules, FilterColumns, Itera
if ($this->query instanceof Traversable) { if ($this->query instanceof Traversable) {
$iterator = $this->query; $iterator = $this->query;
} else { } else {
$iterator = $this->repository->getDataSource()->query($this->query); $iterator = $this->repository->getDataSource($this->target)->query($this->query);
} }
if ($iterator instanceof IteratorAggregate) { if ($iterator instanceof IteratorAggregate) {