Skip to content

Commit 4e3b785

Browse files
maddhatterShawn Tunney
andauthored
Fix computed columns mapping to wrong tables (#51009)
Co-authored-by: Shawn Tunney <[email protected]>
1 parent 94f0192 commit 4e3b785

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function compileColumns($schema, $table)
125125
.'join sys.schemas as scm on obj.schema_id = scm.schema_id '
126126
.'left join sys.default_constraints def on col.default_object_id = def.object_id and col.object_id = def.parent_object_id '
127127
."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' "
128-
.'left join sys.computed_columns as com on col.column_id = com.column_id '
128+
.'left join sys.computed_columns as com on col.column_id = com.column_id and col.object_id = com.object_id '
129129
."where obj.type in ('U', 'V') and obj.name = %s and scm.name = %s "
130130
.'order by col.column_id',
131131
$this->quoteString($table),

tests/Integration/Database/SqlServer/DatabaseSqlServerSchemaBuilderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ protected function afterRefreshingDatabase()
2121
protected function destroyDatabaseMigrations()
2222
{
2323
Schema::drop('users');
24+
Schema::dropIfExists('computed');
2425
DB::statement('drop view if exists users_view');
2526
}
2627

@@ -64,4 +65,12 @@ public function testGetViewsWhenNoneExist()
6465
{
6566
$this->assertSame([], Schema::getViews());
6667
}
68+
69+
public function testComputedColumnsListing()
70+
{
71+
DB::statement('create table dbo.computed (id int identity (1,1) not null, computed as id + 1)');
72+
73+
$userColumns = Schema::getColumns('users');
74+
$this->assertNull($userColumns[1]['generation']);
75+
}
6776
}

0 commit comments

Comments
 (0)