Skip to content

Commit f2be22f

Browse files
committed
PHPORM-82 Support prefix for collection names
1 parent f93aaa7 commit f2be22f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Connection.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function __construct(array $config)
6666
// Select database
6767
$this->db = $this->connection->selectDatabase($this->getDefaultDatabaseName($dsn, $config));
6868

69+
$this->tablePrefix = $config['prefix'] ?? '';
70+
6971
$this->useDefaultPostProcessor();
7072

7173
$this->useDefaultSchemaGrammar();
@@ -84,7 +86,7 @@ public function collection($collection)
8486
{
8587
$query = new Query\Builder($this, $this->getQueryGrammar(), $this->getPostProcessor());
8688

87-
return $query->from($collection);
89+
return $query->from($this->tablePrefix . $collection);
8890
}
8991

9092
/**
@@ -109,7 +111,7 @@ public function table($table, $as = null)
109111
*/
110112
public function getCollection($name)
111113
{
112-
return new Collection($this, $this->db->selectCollection($name));
114+
return new Collection($this, $this->db->selectCollection($this->tablePrefix . $name));
113115
}
114116

115117
/** @inheritdoc */

0 commit comments

Comments
 (0)