Skip to content

Commit

Permalink
Add prefix to the table name before querying a column type. (#13136)
Browse files Browse the repository at this point in the history
  • Loading branch information
willrowe authored and taylorotwell committed Apr 13, 2016
1 parent fbb4bda commit 5740581
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public function hasColumns($table, array $columns)
*/
public function getColumnType($table, $column)
{
$table = $this->connection->getTablePrefix().$table;

return $this->connection->getDoctrineColumn($table, $column)->getType()->getName();
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Database/DatabaseSchemaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,20 @@ public function testTableHasColumns()
$this->assertTrue($builder->hasColumns('users', ['id', 'firstname']));
$this->assertFalse($builder->hasColumns('users', ['id', 'address']));
}

public function testGetColumnTypeAddsPrefix()
{
$connection = m::mock('Illuminate\Database\Connection');
$column = m::mock('StdClass');
$type = m::mock('StdClass');
$grammar = m::mock('StdClass');
$connection->shouldReceive('getSchemaGrammar')->once()->andReturn($grammar);
$builder = new Builder($connection);
$connection->shouldReceive('getTablePrefix')->once()->andReturn('prefix_');
$connection->shouldReceive('getDoctrineColumn')->once()->with('prefix_users', 'id')->andReturn($column);
$column->shouldReceive('getType')->once()->andReturn($type);
$type->shouldReceive('getName')->once()->andReturn('integer');

$this->assertEquals($builder->getColumnType('users', 'id'), 'integer');
}
}

0 comments on commit 5740581

Please sign in to comment.