             }
             
             // 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])
             }
             

    
    mutating func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
        defer { currentIndex += 1 }
        let decoder = _RowDecoder<R>(row: rows[currentIndex], codingPath: codingPath,
                                     keyDecodingStrategy: .useDefaultKeys)
        return try T(from: decoder)
    }
    

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