             }
             
             // Scope? (beware left joins: check if scoped row contains non-null values)
-            if let scopedRow = row.scopesTree[keyName], scopedRow.containsNonNullValue {
+            if let scopedRow = row.scopesTree[key.stringValue], scopedRow.containsNonNullValue {
                 return try decode(type, fromRow: scopedRow, codingPath: codingPath + [key])
             }
             

        
        func decodeIfPresent<T>(_ type: T.Type, forKey key: Key) throws -> T? where T: Decodable {
            let row = decoder.row
            let keyName = key.stringValue
            
            // Column?
            if let index = row.index(forColumn: keyName) {
                // Prefer DatabaseValueConvertible decoding over Decodable.
                // This allows decoding Date from String, or DatabaseValue from NULL.
                if type == Date.self {

            // Nil is only possible for columns and scopes (optional
            // associations), not for prefetched rows.
            let row = decoder.row
            return row[column(forKey: key)] == nil && (row.scopesTree[key.stringValue] == nil)
        }
        
        // swiftlint:disable comma
