@@ -27,7 +27,18 @@ module.exports = function processNativeRecord(nativeRecord, WLModel, meta) {
2727
2828 // Check out each known attribute...
2929 Object . entries ( WLModel . attributes ) . forEach ( ( [ attrName , attrDef ] ) => {
30- const phRecordKey = attrDef . columnName
30+ // Use columnName if defined, otherwise fall back to attribute name
31+ const columnName = attrDef . columnName || attrName
32+
33+ // If columnName differs from attrName, we need to rename the key
34+ // SQLite returns data with column names, but Waterline expects attribute names
35+ if ( columnName !== attrName && nativeRecord [ columnName ] !== undefined ) {
36+ nativeRecord [ attrName ] = nativeRecord [ columnName ]
37+ delete nativeRecord [ columnName ]
38+ }
39+
40+ // Now work with the attribute name
41+ const phRecordKey = attrName
3142
3243 // Handle JSON type
3344 if (
@@ -69,12 +80,14 @@ module.exports = function processNativeRecord(nativeRecord, WLModel, meta) {
6980 // Handle Boolean type
7081 if ( attrDef . type === 'boolean' ) {
7182 // SQLite stores booleans as integers (0 = false, 1 = true)
72- // But they come back as strings, so we need to parse them first
83+ // Values may come back as numbers (1, 1.0) or strings ('1', '1.0')
7384 const rawValue = nativeRecord [ phRecordKey ]
7485 if ( rawValue !== undefined && rawValue !== null ) {
75- const numericValue =
76- typeof rawValue === 'string' ? parseFloat ( rawValue ) : rawValue
77- nativeRecord [ phRecordKey ] = numericValue === 0 ? false : true
86+ if ( typeof rawValue !== 'boolean' ) {
87+ const numericValue =
88+ typeof rawValue === 'string' ? parseFloat ( rawValue ) : rawValue
89+ nativeRecord [ phRecordKey ] = numericValue !== 0
90+ }
7891 }
7992 }
8093
0 commit comments