Skip to content
Closed
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
3 changes: 2 additions & 1 deletion lib/src/models/row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class Row implements Model {
$createdAt: map['\$createdAt'].toString(),
$updatedAt: map['\$updatedAt'].toString(),
$permissions: List.from(map['\$permissions'] ?? []),
data: map["data"] ?? map,
// Assign the entire map to data
data: map,
);
}

Expand Down
56 changes: 56 additions & 0 deletions test/src/models/row_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,61 @@ void main() {
expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00');
expect(result.$permissions, []);
});

// Test for the specific bug
//reported in issue #281
test('fromMap should handle columns named data without type errors', () {
final map = {
'\$id': 'row123',
'\$sequence': 1,
'\$tableId': 'table1',
'\$databaseId': 'db1',
'\$createdAt': '2023-01-01T00:00:00.000Z',
'\$updatedAt': '2023-01-01T00:00:00.000Z',
'\$permissions': ['read', 'write'],
'data':
'this is a string value in data column', // This column name was causing the issue
'name': 'Test Row',
'value': 42,
};

// This should not throw a TypeError anymore
final row = Row.fromMap(map);

// Verify that data contains the complete map
expect(row.data, isA<Map<String, dynamic>>());
expect(row.data['data'], equals('this is a string value in data column'));
expect(row.data['name'], equals('Test Row'));
expect(row.data['value'], equals(42));
expect(row.data['\$id'], equals('row123'));

// Verify that the main fields are assigned correctly
expect(row.$id, equals('row123'));
expect(row.$sequence, equals(1));
});

// Additional test to verify behavior when there's no data column
test('fromMap should work correctly when map does not contain data column',
() {
final map = {
'\$id': 'row456',
'\$sequence': 2,
'\$tableId': 'table1',
'\$databaseId': 'db1',
'\$createdAt': '2023-01-01T00:00:00.000Z',
'\$updatedAt': '2023-01-01T00:00:00.000Z',
'\$permissions': ['read'],
'name': 'Another Row',
'value': 100,
// No data column - this should work fine
};

final row = Row.fromMap(map);

expect(row.data, isA<Map<String, dynamic>>());
expect(row.data['name'], equals('Another Row'));
expect(row.data['value'], equals(100));
expect(row.$id, equals('row456'));
});
});
}