diff --git a/lib/src/models/row.dart b/lib/src/models/row.dart index 28a8896..f64ece6 100644 --- a/lib/src/models/row.dart +++ b/lib/src/models/row.dart @@ -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, ); } diff --git a/test/src/models/row_test.dart b/test/src/models/row_test.dart index fed01ff..325abbf 100644 --- a/test/src/models/row_test.dart +++ b/test/src/models/row_test.dart @@ -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>()); + 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>()); + expect(row.data['name'], equals('Another Row')); + expect(row.data['value'], equals(100)); + expect(row.$id, equals('row456')); + }); }); }