Skip to content

Commit

Permalink
Fix computed columns mapping to wrong tables (#51009)
Browse files Browse the repository at this point in the history
Co-authored-by: Shawn Tunney <[email protected]>
  • Loading branch information
maddhatter and Shawn Tunney authored Apr 10, 2024
1 parent 94f0192 commit 4e3b785
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function compileColumns($schema, $table)
.'join sys.schemas as scm on obj.schema_id = scm.schema_id '
.'left join sys.default_constraints def on col.default_object_id = def.object_id and col.object_id = def.parent_object_id '
."left join sys.extended_properties as prop on obj.object_id = prop.major_id and col.column_id = prop.minor_id and prop.name = 'MS_Description' "
.'left join sys.computed_columns as com on col.column_id = com.column_id '
.'left join sys.computed_columns as com on col.column_id = com.column_id and col.object_id = com.object_id '
."where obj.type in ('U', 'V') and obj.name = %s and scm.name = %s "
.'order by col.column_id',
$this->quoteString($table),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected function afterRefreshingDatabase()
protected function destroyDatabaseMigrations()
{
Schema::drop('users');
Schema::dropIfExists('computed');
DB::statement('drop view if exists users_view');
}

Expand Down Expand Up @@ -64,4 +65,12 @@ public function testGetViewsWhenNoneExist()
{
$this->assertSame([], Schema::getViews());
}

public function testComputedColumnsListing()
{
DB::statement('create table dbo.computed (id int identity (1,1) not null, computed as id + 1)');

$userColumns = Schema::getColumns('users');
$this->assertNull($userColumns[1]['generation']);
}
}

0 comments on commit 4e3b785

Please sign in to comment.