Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix computed columns mapping to wrong tables #51009

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
}
}