mirror of https://github.com/AMT-Cheif/drift.git
Properly handle overridden elements when parsing columns
This commit is contained in:
parent
337e260667
commit
0b9d4c897b
|
@ -110,13 +110,21 @@ class TableParser {
|
|||
}
|
||||
|
||||
Future<List<SpecifiedColumn>> _parseColumns(ClassElement element) {
|
||||
final columns = element.allSupertypes
|
||||
final columnNames = element.allSupertypes
|
||||
.map((t) => t.element)
|
||||
.followedBy([element])
|
||||
.expand((e) => e.fields)
|
||||
.where((field) => isColumn(field.type) && field.getter != null);
|
||||
.where((field) => isColumn(field.type) && field.getter != null)
|
||||
.map((field) => field.name)
|
||||
.toSet();
|
||||
|
||||
return Future.wait(columns.map((field) async {
|
||||
final fields = columnNames.map((name) {
|
||||
final getter = element.getGetter(name) ??
|
||||
element.lookUpInheritedConcreteGetter(name, element.library);
|
||||
return getter.variable;
|
||||
});
|
||||
|
||||
return Future.wait(fields.map((field) async {
|
||||
final resolved = await base.loadElementDeclaration(field.getter);
|
||||
final node = resolved.node as MethodDeclaration;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ void main() {
|
|||
}
|
||||
|
||||
class Foos extends HasNameTable with IntIdTable {
|
||||
|
||||
TextColumn get name => text().nullable()();
|
||||
}
|
||||
'''
|
||||
});
|
||||
|
@ -159,6 +159,7 @@ void main() {
|
|||
test('handles inheritance in column definitions', () async {
|
||||
final table = await parse('Foos');
|
||||
|
||||
expect(table.columns, hasLength(2));
|
||||
expect(table.columns.map((c) => c.name.name), containsAll(['id', 'name']));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue