     /// Returns a boolean indicating whether this record and the other record
     /// have the same database representation.
     public func databaseEquals(_ record: Self) -> Bool {
-        return databaseChangesIterator(from: record).next() == nil
+        return databaseChangesIterator(from: PersistenceContainer(record)).next() == nil
     }
 
     /// A dictionary of values changed from the other record.

    /// same set of columns in their `encode(to:)` method, only the columns
    /// defined by the receiver record are considered.
    public func databaseChanges(from record: MutablePersistableRecord) -> [String: DatabaseValue] {
        return Dictionary(uniqueKeysWithValues: databaseChangesIterator(from: record))
    }
    
    fileprivate func databaseChangesIterator(from record: MutablePersistableRecord) -> AnyIterator<(String, DatabaseValue)> {
        let oldContainer = PersistenceContainer(record)
        var newValueIterator = PersistenceContainer(self).makeIterator()
        return AnyIterator {
            // Loop until we find a change, or exhaust columns:

        try update(db, columns: Set(columns.map { $0.name }))
    }
    
    /// If the record has any difference from the other record, executes an
    /// UPDATE statement so that those differences and only those difference are
    /// saved in the database.
    ///
    /// This method is guaranteed to have saved the eventual differences in the
    /// database if it returns without error.
    ///
    /// For example:
    ///
    ///     if let oldPlayer = Player.fetchOne(db, key: 42) {
    ///         var newPlayer = oldPlayer
    ///         newPlayer.score += 10
    ///         newPlayer.hasAward = true
    ///         try newPlayer.updateChanges(db, from: oldRecord)
    ///     }
    ///
    /// - parameter db: A database connection.
    /// - parameter record: The comparison record.
    /// - returns: Whether the record had changes.
    /// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
    ///   PersistenceError.recordNotFound is thrown if the primary key does not
    ///   match any row in the database and record could not be updated.
    /// - SeeAlso: updateChanges(_:with:)
    @discardableResult
    public func updateChanges(_ db: Database, from record: MutablePersistableRecord) throws -> Bool {
        let oldContainer = PersistenceContainer(record)
        let changes = databaseChangesIterator(from: oldContainer)
        let changedColumns: Set<String> = changes.reduce(into: []) { $0.insert($1.0) }
        if changedColumns.isEmpty {
            return false
        } else {
            try update(db, columns: changedColumns)
            return true
        }
    }
    
    /// Mutates the record according to the provided closure, and then, if the
    /// record has any difference from its previous version, executes an
    /// UPDATE statement so that those differences and only those difference are
    /// saved in the database.
    ///
    /// This method is guaranteed to have saved the eventual differences in the
    /// database if it returns without error.
    ///
    /// For example:
    ///
    ///     if var player = Player.fetchOne(db, key: 42) {
    ///         try player.updateChanges(db) {
    ///             $0.score += 10
    ///             $0.hasAward = true
    ///         }
    ///     }
    ///
    /// - parameter db: A database connection.
    /// - parameter change: A closure that modifise the record.
    /// - returns: Whether the record had changes.
    /// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
    ///   PersistenceError.recordNotFound is thrown if the primary key does not
    ///   match any row in the database and record could not be updated.
    @discardableResult
    public mutating func updateChanges(_ db: Database, with change: (inout Self) throws -> Void) throws -> Bool {
        let oldContainer = PersistenceContainer(self)
        try change(&self)
        let changes = databaseChangesIterator(from: oldContainer)
        let changedColumns: Set<String> = changes.reduce(into: []) { $0.insert($1.0) }
        if changedColumns.isEmpty {
            return false
        } else {
