Skip to content

Commit 9389731

Browse files
committed
fixed database table prefixing
1 parent 2edbb89 commit 9389731

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/Cmgmyr/Messenger/Models/Thread.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function scopeForUserWithNewMessages($query, $userId)
117117
->where('participants.user_id', $userId)
118118
->whereNull('participants.deleted_at')
119119
->where(function ($query) {
120-
$query->where('threads.updated_at', '>', $this->getConnection()->raw('participants.last_read'))
120+
$query->where('threads.updated_at', '>', $this->getConnection()->raw($this->getConnection()->getTablePrefix() . 'participants.last_read'))
121121
->orWhereNull('participants.last_read');
122122
})
123123
->select('threads.*')
@@ -240,16 +240,16 @@ private function createSelectString($columns)
240240
switch ($dbDriver) {
241241
case 'pgsql':
242242
case 'sqlite':
243-
$columnString = implode(" || ' ' || users.", $columns);
244-
$selectString = "(users." . $columnString . ") as name";
243+
$columnString = implode(" || ' ' || " . $this->getConnection()->getTablePrefix() . "users.", $columns);
244+
$selectString = "(" . $this->getConnection()->getTablePrefix() . "users." . $columnString . ") as name";
245245
break;
246246
case 'sqlsrv':
247-
$columnString = implode(" + ' ' + users.", $columns);
248-
$selectString = "(users." . $columnString . ") as name";
247+
$columnString = implode(" + ' ' + " . $this->getConnection()->getTablePrefix() . "users.", $columns);
248+
$selectString = "(" . $this->getConnection()->getTablePrefix() . "users." . $columnString . ") as name";
249249
break;
250250
default:
251-
$columnString = implode(", ' ', users.", $columns);
252-
$selectString = "concat(users." . $columnString . ") as name";
251+
$columnString = implode(", ' ', " . $this->getConnection()->getTablePrefix() . "users.", $columns);
252+
$selectString = "concat(" . $this->getConnection()->getTablePrefix() . "users." . $columnString . ") as name";
253253
}
254254

255255
return $selectString;

tests/EloquentThreadTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ public function it_should_generate_participant_select_string()
220220

221221
$columns = ['name'];
222222
$select = $method->invokeArgs($thread, [$columns]);
223-
$this->assertEquals("(users.name) as name", $select);
223+
$this->assertEquals("(" . Eloquent::getConnectionResolver()->getTablePrefix() . "users.name) as name", $select);
224224

225225
$columns = ['first_name', 'last_name'];
226226
$select = $method->invokeArgs($thread, [$columns]);
227-
$this->assertEquals("(users.first_name || ' ' || users.last_name) as name", $select);
227+
$this->assertEquals("(" . Eloquent::getConnectionResolver()->getTablePrefix() . "users.first_name || ' ' || " . Eloquent::getConnectionResolver()->getTablePrefix() . "users.last_name) as name", $select);
228228

229229
$columns = ['first_name', 'last_name', 'email'];
230230
$select = $method->invokeArgs($thread, [$columns]);
231-
$this->assertEquals("(users.first_name || ' ' || users.last_name || ' ' || users.email) as name", $select);
231+
$this->assertEquals("(" . Eloquent::getConnectionResolver()->getTablePrefix() . "users.first_name || ' ' || " . Eloquent::getConnectionResolver()->getTablePrefix() . "users.last_name || ' ' || " . Eloquent::getConnectionResolver()->getTablePrefix() . "users.email) as name", $select);
232232
}
233233

234234
/** @test */

tests/TestCase.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ function ($table) {
8282
*/
8383
private function seedUsersTable()
8484
{
85-
DB::insert('INSERT INTO users (id, first_name, last_name, email, created_at, updated_at) VALUES (?, ?, ?, ?, datetime(), datetime())', [1, 'Chris', 'Gmyr', '[email protected]']);
86-
DB::insert('INSERT INTO users (id, first_name, last_name, email, created_at, updated_at) VALUES (?, ?, ?, ?, datetime(), datetime())', [2, 'Adam', 'Wathan', '[email protected]']);
87-
DB::insert('INSERT INTO users (id, first_name, last_name, email, created_at, updated_at) VALUES (?, ?, ?, ?, datetime(), datetime())', [3, 'Taylor', 'Otwell', '[email protected]']);
85+
DB::insert('INSERT INTO ' . DB::getTablePrefix() . 'users (id, first_name, last_name, email, created_at, updated_at) VALUES (?, ?, ?, ?, datetime(), datetime())', [1, 'Chris', 'Gmyr', '[email protected]']);
86+
DB::insert('INSERT INTO ' . DB::getTablePrefix() . 'users (id, first_name, last_name, email, created_at, updated_at) VALUES (?, ?, ?, ?, datetime(), datetime())', [2, 'Adam', 'Wathan', '[email protected]']);
87+
DB::insert('INSERT INTO ' . DB::getTablePrefix() . 'users (id, first_name, last_name, email, created_at, updated_at) VALUES (?, ?, ?, ?, datetime(), datetime())', [3, 'Taylor', 'Otwell', '[email protected]']);
8888
}
8989

9090
/**

0 commit comments

Comments
 (0)